对于C.TheFootballSeason(枚举)(CodeforcesRound#592(Div.2))感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍枚举的规则是什么,并为您提供关于Code
对于C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍枚举的规则是什么,并为您提供关于Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))、Codeforces 1099 A. Snowball - 暴力 (Codeforces Round #530 (Div. 2))、codeforces 920 EFG 题解合集 ( Educational Codeforces Round 37 )、codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟的有用信息。
本文目录一览:- C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )(枚举的规则是什么)
- Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))
- Codeforces 1099 A. Snowball - 暴力 (Codeforces Round #530 (Div. 2))
- codeforces 920 EFG 题解合集 ( Educational Codeforces Round 37 )
- codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟
C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )(枚举的规则是什么)
The football season has just ended in Berland. According to the rules of Berland football,each match is played between two teams. The result of each match is either a draw,or a victory of one of the playing teams. If a team wins the match,it gets ww points,and the opposing team gets 00 points. If the game results in a draw,both teams get dd points.
The manager of the Berland capital team wants to summarize the results of the season,but,unfortunately,all information about the results of each match is lost. The manager only kNows that the team has played nn games and got pp points for them.
You have to determine three integers xx, yy and zz — the number of wins,draws and loses of the team. If there are multiple answers,print any of them. If there is no suitable triple (x,y,z)(x,y,z),report about it.
The first line contains four integers nn, pp, ww and dd (1≤n≤1012,0≤p≤1017,1≤d<w≤105)(1≤n≤1012,0≤p≤1017,1≤d<w≤105) — the number of games,the number of points the team got,the number of points awarded for winning a match,and the number of points awarded for a draw,respectively. Note that w>dw>d,so the number of points awarded for winning is strictly greater than the number of points awarded for draw.
If there is no answer,print −1−1.
Otherwise print three non-negative integers xx, yy and zz — the number of wins,draws and losses of the team. If there are multiple possible triples (x,y,z)(x,print any of them. The numbers should meet the following conditions:
- x⋅w+y⋅d=px⋅w+y⋅d=p,
- x+y+z=nx+y+z=n.
30 60 3 1
17 9 4
10 51 5 4
-1
20 0 15 5
0 0 20
One of the possible answers in the first example — 1717 wins, 99 draws and 44 losses. Then the team got 17⋅3+9⋅1=6017⋅3+9⋅1=60 points in 17+9+4=3017+9+4=30 games.
In the second example the maximum possible score is 10⋅5=5010⋅5=50. Since p=51p=51,there is no answer.
In the third example the team got 00 points,so all 2020 games were lost.
#include <bits/stdc++.h> using namespace std; #define ll long long #define TLE ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll m,n,l,r; int main() { TLE; while(cin>>n>>m>>l>>r) { for(int i=0;i<min(n,l);i++) { if(m-i*r<0) break; if( !((m-i*r)%l) ) { if(i+((m-i*r)/l) <=n ) { cout<<(m-i*r)/l<<" "<<i<<" "<<n-i-(m-i*r)/l<<endl; return 0; } } } cout<<-1<<endl; } return 0; }
Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))
Vasya is reading a e-book. The file of the book consists of nn pages, numbered from 11 to nn. The screen is currently displaying the contents of page xx, and Vasya wants to read the page yy. There are two buttons on the book which allow Vasya to scroll dd pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of 1010 pages, and d=3d=3, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth.
Help Vasya to calculate the minimum number of times he needs to press a button to move to page yy.
The first line contains one integer tt (1≤t≤1031≤t≤103) — the number of testcases.
Each testcase is denoted by a line containing four integers nn, xx, yy, dd (1≤n,d≤1091≤n,d≤109, 1≤x,y≤n1≤x,y≤n) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively.
Print one line for each test.
If Vasya can move from page xx to page yy, print the minimum number of times he needs to press a button to do it. Otherwise print −1−1.
3
10 4 5 2
5 1 3 4
20 4 19 3
4
-1
5
In the first test case the optimal sequence is: 4→2→1→3→54→2→1→3→5.
In the second test case it is possible to get to pages 11 and 55.
In the third test case the optimal sequence is: 4→7→10→13→16→194→7→10→13→16→19.
翻到头只能从头翻,翻到尾只能从尾倒着翻。
代码:
1 //A
2 #include<bits/stdc++.h>
3 using namespace std;
4 typedef long long ll;
5 const int maxn=1e5+10;
6 const int inf=0x3f3f3f3f;
7
8 int main()
9 {
10 int t;
11 cin>>t;
12 while(t--){
13 int n,x,y,d,ans=inf;
14 cin>>n>>x>>y>>d;
15 if(abs(y-x)%d==0) {ans=min(ans,abs(y-x)/d);}
16 if((y-1)%d==0) {ans=min(ans,x/d+(y-1)/d+(x%d==0?0:1));}
17 if((n-y)%d==0) {ans=min(ans,(n-x)/d+(n-y)/d+((n-x)%d==0?0:1));}
18 if(ans==inf) cout<<-1<<endl;
19 else cout<<ans<<endl;
20 }
21 }
Codeforces 1099 A. Snowball - 暴力 (Codeforces Round #530 (Div. 2))
A. Snowball
Today''s morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height hh and it has weight ww. Each second the following sequence of events happens: snowball''s weights increases by ii, where ii — is the current height of snowball, then snowball hits the stone (if it''s present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u1u1 and is located at height d1d1, the second one — u2u2 and d2d2respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.

Find the weight of the snowball when it stops moving, that is, it reaches height 0.
First line contains two integers ww and hh — initial weight and height of the snowball (0≤w≤1000≤w≤100; 1≤h≤1001≤h≤100).
Second line contains two integers u1u1 and d1d1 — weight and height of the first stone (0≤u1≤1000≤u1≤100; 1≤d1≤h1≤d1≤h).
Third line contains two integers u2u2 and d2d2 — weight and heigth of the second stone (0≤u2≤1000≤u2≤100; 1≤d2≤h1≤d2≤h; d1≠d2d1≠d2). Notice that stones always have different heights.
Output a single integer — final weight of the snowball after it reaches height 0.
4 3
1 1
1 2
8
4 3
9 2
0 1
1
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
- The weight of the snowball increases by 3 (current height), becomes equal to 7.
- The snowball moves one meter down, the current height becomes equal to 2.
- The weight of the snowball increases by 2 (current height), becomes equal to 9.
- The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
- The snowball moves one meter down, the current height becomes equal to 1.
- The weight of the snowball increases by 1 (current height), becomes equal to 9.
- The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
- The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
题意就是滚雪球,每下降 1 米,就增加当前高度的重量,如果碰到石头就会减掉石头重量的雪,如果减位负数就是 0,然后从 0 也可以往下滚然后增加。输出最后重量。
代码:
1 //A
2 #include<bits/stdc++.h>
3 using namespace std;
4
5 int main()
6 {
7 int w,h,w1,h1,w2,h2;
8 cin>>w>>h>>w1>>h1>>w2>>h2;
9 for(int i=h;i>=0;i--){
10 w+=i;
11 if(i==h1){
12 w-=w1;
13 if(w<0) w=0;
14 }
15 else if(i==h2){
16 w-=w2;
17 if(w<0) w=0;
18 }
19 }
20 cout<<w<<endl;
21 }
codeforces 920 EFG 题解合集 ( Educational Codeforces Round 37 )
You are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices X such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to X violates this rule.
The first line contains two integers n and m (1 ≤ n ≤ 200000, ).
Then m lines follow, each containing a pair of integers x and y (1 ≤ x, y ≤ n, x ≠ y) denoting that there is no edge between x and y. Each pair is listed at most once; (x, y) and (y, x) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there existsan edge between those vertices.
Firstly print k — the number of connected components in this graph.
Then print k integers — the sizes of components. You should output these integers in non-descending order.
5 5
1 2
3 4
3 2
4 2
2 5
2
1 4
题意:一个无向图,给出没有连边的点对(没有给出的点对都有直接连边),求联通块个数和每个联通块的大小。
题解:首先是存边的问题,不可能把所有边都记录下来吧。那么久只能记录不连通关系了,用邻接表记录的话,询问两个点之间是否有连边不大方便。
可以给每个点开一个 set,set 里面存不连通关系,询问两个点之间是否有连边就在 set 里面查找有没有对应元素就行了。
也可以给每个点开一个 map,当做邻接矩阵用。我采用的是这种。
思路:维护一个集合(set),存储当前不确定在哪个联通块中的点,初始时所有点都在里面。
然后在其中依次取点,dfs 遍历它的联通块,统计一下,把遍历到的点都扔出这个集合,因为它们的连通关系已经确定,不用再对其进行 dfs。
注意:dfs 一个点 x 的时候,要寻找 x 的出边,这样很慢,应该在 set 中依次查找,判断 set 中的点与 x 是否有直接连边。
遍历 set 的时候不要 for (set<int>iterator::it=s.begin ();it!=s.end ();it++) ,由于有删除操作,还是递归删除,所以 it 指向的元素可能在下一层递归中被删掉,然后…… 就 RE 了。可以用 lower_bound () 或 upper_bound () 查找下一个元素,具体见代码。


1 /*
2 Welcome Hacking
3 Wish You High Rating
4 */
5 #include<iostream>
6 #include<cstdio>
7 #include<cstring>
8 #include<ctime>
9 #include<cstdlib>
10 #include<algorithm>
11 #include<cmath>
12 #include<string>
13 #include<map>
14 #include<set>
15 using namespace std;
16 int read(){
17 int xx=0,ff=1;char ch=getchar();
18 while(ch>''9''||ch<''0''){if(ch==''-'')ff=-1;ch=getchar();}
19 while(ch>=''0''&&ch<=''9''){xx=(xx<<3)+(xx<<1)+ch-''0'';ch=getchar();}
20 return xx*ff;
21 }
22 const int maxn=200010;
23 int N,M,t1,t2,temp[maxn],ans;
24 set<int>s;
25 map<int,bool>e[maxn];
26 void dfs(int x){
27 int prev=0;
28 while(1){
29 int t=*s.lower_bound(prev);
30 if(t==(1<<30))
31 break;
32 prev=t+1;
33 if(!e[x][t]){
34 temp[ans]++;
35 s.erase(t);
36 dfs(t);
37 }
38 }
39 }
40 int main(){
41 //freopen("in","r",stdin);
42 N=read(),M=read();
43 for(int i=1;i<=N;i++)
44 s.insert(i);
45 s.insert(1<<30);
46 for(int i=1;i<=M;i++){
47 t1=read(),t2=read();
48 e[t1][t2]=e[t2][t1]=1;
49 }
50 int prev=0;
51 while(1){
52 int t=*s.lower_bound(prev);
53 if(t==(1<<30))
54 break;
55 prev=t+1;
56 s.erase(t);
57 temp[++ans]=1;
58 dfs(t);
59 }
60 sort(temp+1,temp+1+ans);
61 printf("%d\n",ans);
62 for(int i=1;i<=ans;i++)
63 printf("%d ",temp[i]);
64 puts("");
65 return 0;
66 }
Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6).
You are given an array a of n integers. You have to process two types of queries:
- REPLACE l r — for every
replace ai with D(ai);
- SUM l r — calculate
.
Print the answer for each SUM query.
The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the array.
Then m lines follow, each containing 3 integers ti, li, ri denoting i-th query. If ti = 1, then i-th query is REPLACE li ri, otherwise it''s SUM li ri (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).
There is at least one SUM query.
For each SUM query print the answer to it.
7 6
6 4 1 10 3 2 4
2 1 7
2 4 5
1 3 5
2 4 4
1 5 7
2 1 7
30
13
4
22
大意:对于一个给定序列,有两种操作:
1:给定区间 [L,R],将其中的每个元素 x 变为 D (x)
D (x) 是 x 的因子数。
2:给定区间 [L,R],求和。
题解:
线段树套路题。
注意到在 x 属于 1e6 以内时,D (x) 最大是 240.
x,D (x),D (D (x))…… 的衰减速度非常快。
打表可知,对于一个数 1e6 以内的 x,最多进行第一个操作 6 次,就会变成 2(除了 1 , D (1)=1)
先把序列中的所有 1 都换成 2,同时记录一下,方便统计回来。
维护一个线段树记录区间内 1 操作数的次数的最小值和区间和
对于每个 1 操作,暴力修改到线段树底层,直到 1 操作次数最小值大于等于 6.
这样修改的复杂度最差 O (N*logN) (最多修改 6 次,6 是常数)
查询的复杂度为 O (1)
UOJ round 和 hdu 上都有类似的题。


1 /*
2 Welcome Hacking
3 Wish You High Rating
4 */
5 #include<iostream>
6 #include<cstdio>
7 #include<cstring>
8 #include<ctime>
9 #include<cstdlib>
10 #include<algorithm>
11 #include<cmath>
12 #include<string>
13 using namespace std;
14 inline int read(){
15 int xx=0,ff=1;char ch=getchar();
16 while(ch>''9''||ch<''0''){if(ch==''-'')ff=-1;ch=getchar();}
17 while(ch>=''0''&&ch<=''9''){xx=(xx<<3)+(xx<<1)+ch-''0'';ch=getchar();}
18 return xx*ff;
19 }
20 inline int mymin(int xx,int yy)
21 {if(xx<yy)return xx;return yy;}
22 const int maxn=300010,limit=1000000;
23 int N,M,D[limit+10],tot=6,sum[maxn],a[maxn];
24 struct Segment_Tree{
25 long long sum;
26 }T[maxn*4];
27 int x,y,opt;
28 void build(int L,int R,int root){
29 if(L==R){
30 T[root].sum=a[L];
31 return;
32 }
33 int mid=(L+R)>>1;
34 build(L,mid,root*2);
35 build(mid+1,R,root*2+1);
36 T[root].sum=T[root*2].sum+T[root*2+1].sum;
37 }
38 void upd(int L,int R,int root){
39 if(T[root].sum==(R-L+1)*2)
40 return;
41 if(x>R||y<L)
42 return;
43 if(L==R){
44 T[root].sum=D[T[root].sum];
45 return;
46 }
47 int mid=(L+R)>>1;
48 upd(L,mid,root*2);
49 upd(mid+1,R,root*2+1);
50 T[root].sum=T[root*2].sum+T[root*2+1].sum;
51 }
52 long long query(int L,int R,int root){
53 if(x>R||y<L)
54 return 0;
55 if(x<=L&&y>=R)
56 return T[root].sum;
57 int mid=(L+R)>>1;
58 return query(L,mid,root*2)+query(mid+1,R,root*2+1);
59 }
60 int main(){
61 //freopen("in","r",stdin);
62 for(int i=1;i<=limit;i++)
63 for(int j=i;j<=limit;j+=i)
64 D[j]++;
65 N=read(),M=read();
66 for(int i=1;i<=N;i++){
67 a[i]=read();
68 sum[i]=sum[i-1];
69 if(a[i]==1)
70 a[i]=2,sum[i]++;
71 }
72 build(1,N,1);
73 while(M--){
74 opt=read();
75 if(opt==1){
76 x=read(),y=read();
77 upd(1,N,1);
78 }
79 else{
80 x=read(),y=read();
81 printf("%I64d\n",query(1,N,1)-(sum[y]-sum[x-1]));
82 }
83 }
84 return 0;
85 }
Let''s denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of L(x, p)are 1-indexed; for example, 9, 13 and 15 are the first, the second and the third elements of L(7, 22), respectively.
You have to process t queries. Each query is denoted by three integers x, p and k, and the answer to this query is k-th element of L(x, p).
The first line contains one integer t (1 ≤ t ≤ 30000) — the number of queries to process.
Then t lines follow. i-th line contains three integers x, p and k for i-th query (1 ≤ x, p, k ≤ 106).
Print t integers, where i-th integer is the answer to i-th query.
3
7 22 1
7 22 2
7 22 3
9
13
15
5
42 42 42
43 43 43
44 44 44
45 45 45
46 46 46
187
87
139
128
141
大意:t 个询问,给出 x,p,k 求与 p 互质的大于 x 的第 k 个数。
Let''s denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of L(x, p)are 1-indexed; for example, 9, 13 and 15 are the first, the second and the third elements of L(7, 22), respectively.
You have to process t queries. Each query is denoted by three integers x, p and k, and the answer to this query is k-th element of L(x, p).
The first line contains one integer t (1 ≤ t ≤ 30000) — the number of queries to process.
Then t lines follow. i-th line contains three integers x, p and k for i-th query (1 ≤ x, p, k ≤ 106).
Print t integers, where i-th integer is the answer to i-th query.
3
7 22 1
7 22 2
7 22 3
9
13
15
5
42 42 42
43 43 43
44 44 44
45 45 45
46 46 46
187
87
139
128
141
题解:二分加容斥。
每个数的因子可以用筛法筛出来。
然后就是二分查找 ans,容斥原理计算 ans 内有多少个与 p 互质的数。
至于大于 x 嘛,只需用容斥算出小于等于 x 的与 p 互质的数有多少个,加进 k 里面就行了。


1 /*
2 Welcome Hacking
3 Wish You High Rating
4 */
5 #include<iostream>
6 #include<cstdio>
7 #include<cstring>
8 #include<ctime>
9 #include<cstdlib>
10 #include<algorithm>
11 #include<cmath>
12 #include<string>
13 #include<vector>
14 using namespace std;
15 int read(){
16 int xx=0,ff=1;char ch=getchar();
17 while(ch>''9''||ch<''0''){if(ch==''-'')ff=-1;ch=getchar();}
18 while(ch>=''0''&&ch<=''9''){xx=(xx<<3)+(xx<<1)+ch-''0'';ch=getchar();}
19 return xx*ff;
20 }
21 const int limit=1000000;
22 vector<int>V[limit+5];
23 void get_fac(){
24 for(int i=2;i<=limit;i++)
25 if(!V[i].size())
26 for(int j=i;j<=limit;j+=i)
27 V[j].push_back(i);
28 }
29 int x,p,k,delta;
30 int L,R,mid;
31 int calc(int num,int rb){
32 int siz=V[num].size();
33 int re=0;
34 for(int i=1;i<(1<<siz);i++){
35 int s=1,tim=0;
36 for(int j=0;j<siz;j++)
37 if((i>>j)&1)
38 s*=V[num][j],tim++;
39 if(tim&1)
40 re+=rb/s;
41 else
42 re-=rb/s;
43 }
44 return rb-re;
45 }
46 int main(){
47 //freopen("in","r",stdin);
48 get_fac();
49 for(int T=read();T;T--){
50 x=read(),p=read(),k=read();
51 delta=calc(p,x);
52 L=x,R=int(1e8);
53 while(L+1<R){
54 mid=(L+R)/2;
55 if(calc(p,mid)-delta>=k)
56 R=mid;
57 else
58 L=mid;
59 }
60 printf("%d\n",R);
61 }
62 return 0;
63 }
codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char x[105];
char xx[105];
int main() {
int t;
cin>>t;
while(t--) {
int a,b,c,n;
cin>>n>>a>>b>>c;
for(int i=0; i<n; i++) xx[i]=0;
scanf("%s",x);
int r=0,p=0,s=0;
for(int i=0; i<n; i++) {
if(x[i]==''R'') r++;
else if(x[i]==''P'') p++;
else s++;
}
int ans=0;
ans+=min(r,b);
ans+=min(p,c);
ans+=min(s,a);
if(ans>=(n+1)/2) {
printf("YES\n");
for(int i=0; i<n; i++) {
if(x[i]==''R''&&b>0) {
xx[i]=''P'';
b--;
} else if(x[i]==''P''&&c>0) {
xx[i]=''S'';
c--;
} else if(x[i]==''S''&&a>0) {
a--;
xx[i]=''R'';
}
}
for(int i=0; i<n; i++) {
if(xx[i]==0) {
if(a>0) {
printf("R");
a--;
} else if(b>0) {
printf("P");
b--;
} else if(c>0) {
c--;
printf("S");
}
} else printf("%c",xx[i]);
}
printf("\n");
} else {
printf("NO\n");
}
}
return 0;
}
关于C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )和枚举的规则是什么的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))、Codeforces 1099 A. Snowball - 暴力 (Codeforces Round #530 (Div. 2))、codeforces 920 EFG 题解合集 ( Educational Codeforces Round 37 )、codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟的相关知识,请在本站寻找。
本文标签: