Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
Description
Kennethsnow
and Hlwt
both love football.
One day, Kennethsnow
wants to review the match in 2003 between AC Milan and Juventus for the Championship Cup. But before the penalty shootout. he fell asleep.
The next day, he asked Hlwt
for the result. Hlwt
said that it scoreda :b in the penalty shootout.
Kennethsnow
had some doubt about what Hlwt
said becauseHlwt
is a fan of Juventus but Kennethsnow
loves AC Milan.
So he wanted to know whether the result can be a legal result of a penalty shootout. If it can be, outputYes
, otherwise output No
.
The rule of penalty shootout is as follows:
There will be 5 turns, in each turn, 2 teams each should take a penalty shoot. If goal, the team get 1 point. After each shoot, if the winner can be confirmed(i.e: no matter what happened after this shoot, the winner will not change), the match end immediately.
If after 5 turns the 2 teams score the same point. A new turn will be added, until that one team get a point and the other not in a turn.
Before the penalty shootout begins, the chief referee will decide which team will take the shoot first, and afterwards, two teams will take shoot one after the other. Since Kennethsnow fell asleep last night, he had no idea whether AC Milan or Juventus took the first shoot.
Input
The only line contains 2 integers a,b. Means the result that Hlwt
said.
0≤a,b≤10
Output
Output a string Yes
or No
, means whether the result is legal.
Sample Input
3 2
2 5Sample Output
Yes
NoHint
The Sample 1 is the actual result of the match in 2003.
The Sample 2, when it is 2:4 after 4 turns, AC Milan can score at most 1 point in the next turn. So Juventus has win when it is 2:4. So the result cannot be 2:5.
This story happened in a parallel universe. In this world where we live, kennethsnow
is a fan of Real Madrid.
Source
因为是问是否确定所以要逐个球比较。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; bool work(int a, int b) { if(a == b) return false; if(a > 5 || b > 5) { if(abs(a - b) == 1) return true; else return false; } if(a == 5 || b == 5) { if(b < 3 || a < 3) return false; else return true; } if(a == 4 || b == 4) { if(a == 0 || b == 0) return false; else return true; } if(a == 3 || b == 3) { return true; } return true; } int main() { int a, b; while(~scanf("%d%d", &a, &b)) { if(work(a, b)) puts("Yes"); else puts("No"); } return 0; }
Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
Description
Given an integer Y, you need to find the minimal integer K so that there exists a X satisfying X−Y=Z(Z≥0) and the number of different digit between X and Z is K under decimal system.
For example: Y=1, you can find a X=100 so that Z=99 and K is 3 due to 1≠0 and 0≠9. But for minimization, we should let X=1 so that Z=0 and K can just be 1.
Input
Only one integer Y(0≤Y≤1018).
Output
The minimal K.
Sample Input
1
191Sample Output
1
2Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; int a[25]; int ans; void dfs(int cur, int cnt, int tp, int kg) { if(cur >= tp) { ans = max(ans, cnt); return; } if(a[cur] == 0) { if(kg != 9 && !(cur == tp - 2 && a[tp - 1] == 9)) dfs(cur + 1, cnt + 1, tp, 0); else dfs(cur + 1, cnt, tp, 1); } else if(a[cur] == 9) { if((kg == 1 || kg == 9) && cur != tp - 1 && cur != 0) dfs(cur + 1, cnt + 1, tp, 9); else dfs(cur + 1, cnt, tp, 1); } else dfs(cur + 1, cnt, tp, 1); } int main() { LL Y; while(~scanf("%lld", &Y)) { int tp = 0; while(Y) { a[tp++] = Y % 10; Y /= 10; } ans = 0; dfs(0, 0, tp, 1); printf("%d\n", tp - ans); } return 0; } //这是自己写的模拟的代码,一直WA4。。。,还不懂 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define ll long long using namespace std; char a[20],b[20],s[20],ss[20]; int main() { int i,j; while(scanf("%s",ss)!=EOF) { memset(a,'\0',sizeof(a)); memset(b,'\0',sizeof(b)); memset(s,'\0',sizeof(s)); int len=strlen(ss),k=0; for(i=len-1;i>=0;i--) s[k++]=ss[i]; if(s[0]!='0') a[0]=s[0]-1; else a[0]='0'; int l,r; for(i=1;i<k-1;) { if(s[i]!='0') { a[i]=s[i]-1; i++; } else { l=i; while(s[i]=='0') i++; r=i; if(r-l<=1) a[l]='0'; else { a[l]='1'; for(j=l+1;j<r;j++) a[j]='0'; } } } a[k-1]=s[k-1]+1; ll n=0,m=0,nm; for(i=k-1;i>=0;i--) n=n*10+(a[i]-'0'); for(i=0;i<len;i++) m=m*10+(ss[i]-'0'); nm=n-m; k=0; while(nm) { b[k++]=nm%10+'0'; nm/=10; } for(i=k;i<len;i++) b[i]='0'; int cnt=0; for(i=0;i<len;i++) if(b[i]!=a[i]) cnt++; if(ss[0]=='9') cnt++; printf("%d\n",cnt); } return 0; }UESTC - 1041
Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
Description
There is a sequence with n elements. Assuming they are a1,a2,⋯,an.
Please calculate the following expession.
∑1≤i<j≤n(ai∧aj)+(ai|aj)+(ai&aj)
In the expression above, ^
|
&
is bit operation. If you don’t know bit operation, you can visit
http://en.wikipedia.org/wiki/Bitwise_operation
to get some useful information.
Input
The first line contains a single integer n, which is the size of the sequence.
The second line contains n integers, the ith integer ai is the ith element of the sequence.
1≤n≤100000,0≤ai≤100000000
Output
Print the answer in one line.
Sample Input
2
1 2
Sample Output
6
Hint
Because the answer is so large, please use long long instead of int. Correspondingly, please use%lld
instead of %d
to scanf and printf.
Large input. You may get Time Limit Exceeded if you use “cin” to get the input. So “scanf” is suggested.
Likewise, you are supposed to use “printf” instead of “cout”.
Source
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN = 1e5 + 100; int num[MAXN][35]; int a[35]; int p[MAXN]; typedef long long LL; int main() { int n; while(~scanf("%d", &n)) { int x; memset(num, 0, sizeof(num)); for(int i = 1; i <= n; i++) { scanf("%d", &x); for(int j = 0; j < 33; j++) { num[i][j] = num[i - 1][j] + x % 2; x = x / 2; } } LL ans = 0; for(int i = 1; i <= n; i++) { for(int j = 0; j < 33; j++) { a[j] = num[i][j] - num[i - 1][j]; } for(int j = 0; j < 33; j++) { int cnt = 0; if(a[j]) { cnt += (i - 1 - num[i - 1][j]);//异或值 cnt += i - 1; //或值 cnt += num[i - 1][j]; //非值 } else { cnt += num[i - 1][j]; cnt += num[i - 1][j]; } ans += (LL)cnt * (1 << j);//得到对应位上的值后再向右移动对应的位数 } } printf("%lld\n", ans); } return 0; }UESTC - 1045
Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
Description
There are n jobs you need to complete. However, complete the ith job you capability must be no less than vi. If you have completed the ith job, your capability will increase ai.
Then the question is coming, what is the minimum initial capability value if you are required to complete all of then jobs.
Note that there is no restriction on the order you complete them. That is to say, you can decide the order by your own.
Input
The first line contains a single integer n, which is the number of jobs you need to complete.
Then each of the following n lines contains2 integers vi and ai, which are described above.
1≤n≤1000,0≤vi≤1000000,0≤ai≤1000
Output
Print the answer in one line.
Sample Input
1
2 1
Sample Output
2
Hint
Source
#include<stdio.h> #include<string.h> #include<algorithm> #define N 1010 using namespace std; struct zz { int v; int w; }p[N]; bool cmp(zz a,zz b) { if(a.v==b.v) return a.w<b.w; return a.v<b.v; } int main() { int n,m,i,j,k; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d%d",&p[i].v,&p[i].w); sort(p,p+n,cmp); int k=p[0].v,kk=0; m=k; for(i=1;i<n;i++) { m+=p[i-1].w; if(m<p[i].v) { kk=p[i].v-m; k+=kk;m+=kk; } } printf("%d\n",k); } return 0; }