如果您想了解CodeForces-1244C-TheFootballSeason-思维的相关知识,那么本文是一篇不可错过的文章,我们将为您提供关于C.TheFootballSeason(枚举)(Cod
如果您想了解CodeForces-1244C-The Football Season-思维的相关知识,那么本文是一篇不可错过的文章,我们将为您提供关于C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )、CF 1244 C - The Football Season、CF 思维联系 --CodeForces -214C (拓扑排序 + 思维 + 贪心)、Codeforce 604C 思维 交替子序列的有价值的信息。
本文目录一览:- CodeForces-1244C-The Football Season-思维
- C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )
- CF 1244 C - The Football Season
- CF 思维联系 --CodeForces -214C (拓扑排序 + 思维 + 贪心)
- Codeforce 604C 思维 交替子序列
CodeForces-1244C-The Football Season-思维
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.
Input
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.
Output
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.
Examples
30 60 3 1
17 9 4
10 51 5 4
-1
20 0 15 5
0 0 20
Note
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.
1 #include<stdio.h> 2 #include<algorithm> 3 #include<string.h> 4 using namespace std; 5 typedef long long ll; 6 7 int main() 8 { 9 ll n,p,w,d; 10 scanf("%lld %lld %lld %lld",&n,&p,&w,&d); 11 if(n*w<p) 12 printf("-1\n"); 13 else if(n*w>=p) 14 { 15 if(n*w==p) 16 { 17 printf("%lld 0 0\n",n); 18 } 19 else if(n*w>p) 20 { 21 ll x=p/w; 22 ll q=p%w;; 23 if(q%d==0) 24 { 25 ll y=q/d; 26 if(x+y<=n) 27 printf("%lld %lld %lld",x,n-x-y); 28 else 29 printf("-1\n"); 30 } 31 else if(q%d!=0)//说明需要从赢的局数点里面分出一部分点进行补充然后给到平局d 32 { 33 //需要求(q+wi)%d==0 34 int flag=0; 35 for(int i=1; i<=min(x,d); i++) 36 { 37 if((q+w*i)%d==0) 38 { 39 ll xx=x-i; 40 ll yy=(q+w*i)/d; 41 ll zz=n-xx-(q+w*i)/d; 42 if(xx+yy+zz<=n) 43 { 44 flag=1; 45 printf("%lld %lld %lld\n",xx,yy,zz); 46 } 47 else 48 printf("-1\n"); 49 break; 50 } 51 } 52 if(!flag) 53 printf("-1\n"); 54 } 55 } 56 } 57 return 0; 58 }
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; }
CF 1244 C - The Football Season
C - The Football Season
先考虑求解
\[ x\times w + y\times d=p \]
若存在一组解
\[ \begin{cases} x_0\y_0 = kw + v & (0<v<w)\\end{cases} \]
则
\[ x_0 \times w + y_0 \times d = p\\Rightarrow x_0 \times w + (kw+v)\times d = p\\Rightarrow x_0\times w + k\times w\times d + v\times d = p\\Rightarrow (x_0+k\times d)\times w + v\times d = p ~~~~~ \]
所以一定存在一组解
\[ \begin{cases} x = x_0 + k\times d\y = v \end{cases} \]
并且由于\(w> d\)
有
\[ x + y = x_0 + k\times d + v < x_0 + k\times w + v \]
前者比后者更有可能成为答案
所以直接枚举所有的v即可
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,p,w,d; int main(){ cin >> n >> p >> w >> d; for(ll v=0;v<w;v++){ if((p - v * d) % w == 0){ ll x = (p - v * d) / w; if(x >= 0 && x + v <= n){ printf("%lld %lld %lld\n",x,v,n-x-v); return 0; } } } puts("-1"); return 0; }
CF 思维联系 --CodeForces -214C (拓扑排序 + 思维 + 贪心)
ACM 思维题训练集合
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let''s number the computers with integers from 1 to 3. Rubik can perform the following actions:
Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours.
题解:
现在有三个工作站,有三种工作,每种工作需要完成前置任务才能进行当前工作,三个工作站之间转换需要花费时间,问将所有任务都完成需要花费的最少时间。一开始可以在任意一个工作站开始工作。
贪心一下,如果在一台电脑上能够完成多项任务,就让他都完成,然后在考虑转移,转移的话无非就是 1-2
2-3 3-1 还有就是 3-2 2-1 1-3 这种,一种是 1 另一种是 2,所以我们不走 1-3 这种用两段 1-2 2-3 代替花费相同,这样在进行拓扑排序完事了。
吐槽一下数据思路错了也能过。
后来想了一下如果一开始三台电脑都能开始一个工作,那么先从哪台开始呢,不知道,所以三台为起始点进行拓扑选最小的的答案输出。
#include <bits/stdc++.h>
using namespace std;
vector<int> mp[15000];
int d[5][5], a[250], deg[250], temp[205], n;
int tooper(int ss)
{
queue<int> s;
int ans = n, cnt = 0, now = ss;
while (1)
{
while (1)
{
int flag = 0;
for (int i = 1; i <= n; ++i)
{
if (deg[i] == 0 && a[i] == now)
{
flag = 1;
deg[i] = -1;
cnt++;
for (int j = 0; j < mp[i].size(); ++j)
{
int v = mp[i][j];
deg[v]--;
}
}
}
if (flag == 0)
break;
}
if (cnt == n)
break;
now++;
ans++;
now = (now == 4 ? 1 : now);
}
return ans;
}
int main()
{
d[1][1] = d[2][2] = d[3][3] = 0;
d[1][2] = d[2][3] = d[3][1] = 1;
d[2][1] = d[3][2] = d[1][3] = 0x3f3f3f3f;
cin>>n;
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i)
{
int k;
scanf("%d", &k);
for (int j = 1; j <= k; ++j)
{
int x;
scanf("%d", &x);
mp[x].push_back(i);
deg[i]++;
}
}
for (int i = 1; i <= n; ++i)
temp[i] = deg[i];
int ans = 0x3f3f3f3f;
for (int i = 1; i <= n; ++i)
deg[i] = temp[i];
ans = min(ans, tooper(1));
for (int i = 1; i <= n; ++i)
deg[i] = temp[i];
ans = min(ans, tooper(2));
for (int i = 1; i <= n; ++i)
deg[i] = temp[i];
ans = min(ans, tooper(3));
printf("%d\n", ans);
}
Codeforce 604C 思维 交替子序列
//思维可能就是找规律看谁找的快吧
原题链接:http://codeforces.com/problemset/problem/604/C
题意:给出一个0和1组成的字符串,可以对任意一段进行翻转,0变1,1变0。求翻转后的最长的交替子序列。
补充:交替子序列:相邻元素不同,可以不连续,但要保持原顺序。如,10011011,交替子序列为10101.
思路:无论如何翻转,对于子序列来说,最多增加一个01或10,所以结果为原来的交替子序列长度加2,再和总长n比较(有可能最长交替子序列就是其本身),取最小值。要找出最长的子序列串,只能翻转不是原来序列里的0和1,因为是0和1互变,翻转区间里原来不交替的翻转后也依然不交替,所以一次只能增加一个01或10。(大佬原话:我想要最长就只能翻转不在最长的01子序列范围内的1个0或1,构成01或10,就可以加二,构成01或10,但是不能超过字符串本来的长度,所以就是min(ct+2,n)//不得不说思路流畅,顺理成章)。
完整代码:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define N 100005 char s[N]; int main(){ int n,t,ct=1; scanf("%d%s",&n,&s); t=s[0]-‘0‘; for(int i=1;i<n;i++){ if((t^(s[i]-‘0‘))==1){ t=s[i]-‘0‘; ct++; } } cout<<min(ct+2,n)<<endl; return 0; }
我们今天的关于CodeForces-1244C-The Football Season-思维的分享就到这里,谢谢您的阅读,如果想了解更多关于C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )、CF 1244 C - The Football Season、CF 思维联系 --CodeForces -214C (拓扑排序 + 思维 + 贪心)、Codeforce 604C 思维 交替子序列的相关信息,可以在本站进行搜索。
本文标签: