Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep universe that we humans have not discovered yet. This year, the TSAB decided to elect an outstanding member from its elite troops. The elected guy will be honored with the title of "Ace of Aces".
After voting, the TSAB received N valid tickets. On each ticket, there is a numberAi denoting the ID of a candidate. The candidate with the most tickets nominated will be elected as the "Ace of Aces". If there are two or more candidates have the same number of nominations, no one will win.
Please write program to help TSAB determine who will be the "Ace of Aces".
< h4< body="">Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer N (1 <= N <= 1000). The next line containsN integers Ai (1 <= Ai <= 1000).
< h4< body="">Output
For each test case, output the ID of the candidate who will be honored with "Ace of Aces". If no one win the election, output "Nobody" (without quotes) instead.
< h4< body="">Sample Input
3 5 2 2 2 1 1 5 1 1 2 2 3 1 998< h4< body="">
Sample Output
2 Nobody 998
Hint
Source
找出出现次数最多的数,如果有多个输出Nobody
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; const int MAXN = 1010; int num[MAXN]; int p[MAXN]; int main(){ int T, N; scanf("%d", &T); while(T--){ memset(num, 0, sizeof(num)); memset(p, 0, sizeof(p)); scanf("%d", &N); int x; for(int i = 0; i < N; i++){ scanf("%d", &x); num[x]++; } int ans = 0, temp = 0; for(int i = 0; i < MAXN; i++){ if(num[i] >= temp){ temp = num[i]; ans = i; p[temp]++; } } if(p[num[ans]] > 1){ puts("Nobody"); } else printf("%d\n", ans); } return 0; }
ZOJ - 3870
Time Limit: 3000MS | Memory Limit: 131072KB | 64bit IO Format: %lld & %llu |
Description
For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team fromN students of his university.
Edward knows the skill level of each student. He has found that if two students with skill levelA and B form a team, the skill level of the team will be A ⊕ B, where ⊕ means bitwise exclusive or. A team will play well if and only if the skill level of the team is greater than the skill level of each team member (i.e.A ⊕ B > max{A, B}).
Edward wants to form a team that will play well in the contest. Please tell him the possible number of such teams. Two teams are considered different if there is at least one different team member.
< h4< body="">Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer N (2 <= N <= 100000), which indicates the number of student. The next line containsN positive integers separated by spaces. The ith integer denotes the skill level ofith student. Every integer will not exceed 109.
< h4< body="">Output
For each case, print the answer in one line.
< h4< body="">Sample Input
2 3 1 2 3 5 1 2 3 4 5< h4< body="">
Sample Output
1 6
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstring> #include<algorithm> const int MAXN = 100010; int a[MAXN], num[100]; typedef long long LL; int geth(int x) { int i; for(i = 0;;i++) { if((1 << i) > x) break; } return i; } int main() { int T, N; scanf("%d", &T); while(T--) { memset(num, 0, sizeof(num)); scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d", a + i); num[geth(a[i])]++; } LL ans = 0; for(int i = 0; i < N; i++) { if(a[i] > 0 && a[i] % 2 == 0) ans += num[0]; for(int j = 1; (1 << (j - 1)) < a[i]; j++) { if((a[i] ^ (1 << (j - 1))) > a[i]) ans += num[j]; } } printf("%lld\n", ans); } return 0; }
ZOJ - 3872
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the arrayA.
< h4< body="">Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line containsN positive integers separated by spaces. Every integer is no larger than 1000000.
< h4< body="">Output
For each case, print the answer in one line.
< h4< body="">Sample Input
3 5 1 2 3 4 5 3 2 3 3 4 2 3 3 2< h4< body="">
Sample Output
105 21 38
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstring> #include<algorithm> #include<set> #include<vector> using namespace std; long long sum[100000+100],pre[100000+100]; int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); memset(sum,0,sizeof(sum)); memset(pre,0,sizeof(pre)); long long ans=0; for(long long i=1;i<=n;i++) { long long x; scanf("%lld",&x); sum[i]=sum[i-1]+(i-pre[x])*x; pre[x]=i; ans+=sum[i]; } printf("%lld\n",ans); } return 0; }
ZOJ - 3875
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
The 999th Zhejiang Provincial Collegiate Programming Contest will be held in Marjar University. The canteen of Marjar University is making preparations for this grand competition. The canteen provides a lunch set of three types: appetizer, main course and dessert. Each type has several dishes with different prices for choosing.
Edward is the headmaster of Marjar University. One day, to inspect the quality of dishes, he go to the canteen and decides to choose amedian set for his lunch. That means he must choose one dish from each of appetizers, main courses and desserts. Each chosen dish should at the median price among all dishes of the same type.
For example, if there are five dessert dishes selling at the price of 2, 3, 5, 10, 30, Edward should choose the dish with price 5 as his dessert since its price is located at the median place of the dessert type. If the number of dishes of a type is even, Edward will choose the dish which is more expensive among the two medians.
You are given the list of all dishes, please write a program to help Edward decide which dishes he should choose.
< h4< body="">Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains three integers S, M and D (1 <=S, M, D <= 100), which means that there are S dishes of appetizer, M dishes of main course and D dishes of dessert.
Then followed by three parts. The first part contains S lines, the second and the last part containsM and D lines respectively. In each line of the three parts, there is a string and an integer indicating the name and the price of a dish. The name of dishes will only consist of non-whitespace characters with no more than 50 characters. The price of dishes are non-negative integers less than or equal to 1000. All dish names will be distinct.
< h4< body="">Output
For each test case, output the total price of the median set, together with the names of appetizer, main course and dessert, separated by a single space.
< h4< body="">Sample Input
2 1 3 2 Fresh_Cucumber 4 Chow_Mein 5 Rice_Served_with_Duck_Leg 12 Fried_Vermicelli 7 Steamed_Dumpling 3 Steamed_Stuffed_Bun 4 2 3 1 Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33 West_Lake_Water_Shield_Soup 36 DongPo's_Braised_Pork 54 West_Lake_Fish_in_Vinegar 48 Longjing_Shrimp 188 DongPo's_Crisp 18< h4< body="">
Sample Output
15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun 108 West_Lake_Water_Shield_Soup DongPo's_Braised_Pork DongPo's_Crisp
Hint
Source
输入三个数,分别代表三个等级的东西有多少
然后按顺序输入每个东西的名字与质量数字,然后对于每个等级选出其质量为中位数的加起来,最后输出
//思路:水题,直接模拟
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { char s[101]; int val; }A[200],B[200],C[200]; bool cmp(node s1,node s2) { return s1.val<s2.val; } int main() { int a,b,c; int t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&a,&b,&c); for(int i=0;i<a;i++) scanf("%s%d",&A[i].s,&A[i].val); for(int i=0;i<b;i++) scanf("%s%d",&B[i].s,&B[i].val); for(int i=0;i<c;i++) scanf("%s%d",&C[i].s,&C[i].val); sort(A,A+a,cmp); sort(B,B+b,cmp); sort(C,C+c,cmp); int ans=0; ans=A[a/2].val+B[b/2].val+C[c/2].val; printf("%d %s %s %s\n",ans,A[a/2].s,B[b/2].s,C[c/2].s); } return 0; }
ZOJ - 3876
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
As a university advocating self-learning and work-rest balance, Marjar University has so many days of rest, including holidays and weekends. Each weekend, which consists of Saturday and Sunday, is a rest time in the Marjar University.
The May Day, also known as International Workers' Day or International Labour Day, falls on May 1st. In Marjar University, the May Day holiday is a five-day vacation from May 1st to May 5th. Due to Saturday or Sunday may be adjacent to the May Day holiday, the continuous vacation may be as long as nine days in reality. For example, the May Day in 2015 is Friday so the continuous vacation is only 5 days (May 1st to May 5th). And the May Day in 2016 is Sunday so the continuous vacation is 6 days (April 30th to May 5th). In 2017, the May Day is Monday so the vacation is 9 days (April 29th to May 7th). How excited!
Edward, the headmaster of Marjar University, is very curious how long is the continuous vacation containing May Day in different years. Can you help him?
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case, there is an integery (1928 <= y <= 9999) in one line, indicating the year of Edward's query.
For each case, print the number of days of the continuous vacation in that year.
3 2015 2016 2017
5 6 9
Input
Output
Sample Input
Sample Output
Hint
Source
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int a[10010]; int vis[10010]; int init() { a[2015]=5; for(int i=2016;i<=10000;i++) { if(i%4==0&&i%100!=0||i%400==0) a[i]=(a[i-1]+2)%7; else a[i]=(a[i-1]+1)%7; } int k=5; for(int i=2015;i>=1928;i--) { if(i%4==0&&i%100!=0||i%400==0) { if(k>=2) a[i-1]=k-2; else { k=k+7; a[i-1]=k-2; } k-=2; } else { if(k>=1) a[i-1]=k-1; else { k+=7; a[i-1]=k-1; } k--; } } } int main() { int t,n; init(); scanf("%d",&t); while(t--) { scanf("%d",&n); if(a[n]==1) printf("9\n"); else if(a[n]==0||a[n]==2) printf("6\n"); else printf("5\n"); } return 0; }
ZOJ - 3878
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY Keyboard with a brokenCaps Lock key, so Edward never presses the brokenCaps Lock key. Luckily, all the other keys on the QWERTY keyboard work well. Every day, he has a lot of documents to type. Thus he needs a converter to translate QWERTY into Dvorak. Can you help him?
The QWERTY Layout and the Dvorak Layout are in the following:
The QWERTY Layout |
---|
The Dvorak Layout |
---|
Input
A QWERTY document Edward typed. The document has no more than 100 kibibytes. And there are no invalid characters in the document.
< h4< body="">Output
The Dvorak document.
< h4< body="">Sample Input
Jgw Gqm Andpw a H.soav Patsfk f;doe Nfk Gq.d slpt a X,dokt vdtnsaohe Kjd yspps,glu pgld; aod yso kd;kgluZ 1234567890 `~!@#$%^&*()}"']_+-=ZQqWEwe{[\| ANIHDYf.,bt/ ABCDEFuvwxyz< h4< body="">
Sample Output
Hi, I'm Abel, a Dvorak Layout user. But I've only a Qwerty keyboard. The following lines are for testing: 1234567890 `~!@#$%^&*()+_-={}[]:"'<>,.?/\| ABCDEFuvwxyz AXJE>Ugk,qf;
Hint
Source
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; char s[10000010]; char c[10000010]; int main() { while(gets(s)!=NULL) { memset(c,'\0',sizeof(c)); int len=strlen(s); for(int i=0;i<len;i++) { if(s[i]=='_') c[i]='{'; else if(s[i]=='-') c[i]='['; else if(s[i]=='+') c[i]='}'; else if(s[i]=='=') c[i]=']'; else if(s[i]=='Q') c[i]='"'; else if(s[i]=='q') c[i]=39; else if(s[i]=='W') c[i]='<'; else if(s[i]=='w') c[i]=','; else if(s[i]=='E') c[i]='>'; else if(s[i]=='e') c[i]='.'; else if(s[i]=='R') c[i]='P'; else if(s[i]=='r') c[i]='p'; else if(s[i]=='T') c[i]='Y'; else if(s[i]=='t') c[i]='y'; else if(s[i]=='Y') c[i]='F'; else if(s[i]=='y') c[i]='f'; else if(s[i]=='U') c[i]='G'; else if(s[i]=='u') c[i]='g'; else if(s[i]=='I') c[i]='C'; else if(s[i]=='i') c[i]='c'; else if(s[i]=='O') c[i]='R'; else if(s[i]=='o') c[i]='r'; else if(s[i]=='P') c[i]='L'; else if(s[i]=='p') c[i]='l'; else if(s[i]=='{') c[i]='?'; else if(s[i]=='[') c[i]='/'; else if(s[i]=='}') c[i]='+'; else if(s[i]==']') c[i]='='; else if(s[i]=='S') c[i]='O'; else if(s[i]=='s') c[i]='o'; else if(s[i]=='D') c[i]='E'; else if(s[i]=='d') c[i]='e'; else if(s[i]=='F') c[i]='U'; else if(s[i]=='f') c[i]='u'; else if(s[i]=='G') c[i]='I'; else if(s[i]=='g') c[i]='i'; else if(s[i]=='H') c[i]='D'; else if(s[i]=='h') c[i]='d'; else if(s[i]=='J') c[i]='H'; else if(s[i]=='j') c[i]='h'; else if(s[i]=='K') c[i]='T'; else if(s[i]=='k') c[i]='t'; else if(s[i]=='L') c[i]='N'; else if(s[i]=='l') c[i]='n'; else if(s[i]==':') c[i]='S'; else if(s[i]==';') c[i]='s'; else if(s[i]=='"') c[i]='_'; else if(s[i]==39) c[i]='-'; else if(s[i]=='Z') c[i]=':'; else if(s[i]=='z') c[i]=';'; else if(s[i]=='X') c[i]='Q'; else if(s[i]=='x') c[i]='q'; else if(s[i]=='C') c[i]='J'; else if(s[i]=='c') c[i]='j'; else if(s[i]=='V') c[i]='K'; else if(s[i]=='v') c[i]='k'; else if(s[i]=='B') c[i]='X'; else if(s[i]=='b') c[i]='x'; else if(s[i]=='N') c[i]='B'; else if(s[i]=='n') c[i]='b'; else if(s[i]=='<') c[i]='W'; else if(s[i]==',') c[i]='w'; else if(s[i]=='>') c[i]='V'; else if(s[i]=='.') c[i]='v'; else if(s[i]=='?') c[i]='Z'; else if(s[i]=='/') c[i]='z'; else c[i]=s[i]; } puts(c); } return 0; }
ZOJ - 3879
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are usually designed to serve as an educational exercise to give participants experience in securing a machine, as well as conducting and reacting to the sort of attacks found in the real world. Reverse-engineering, network sniffing, protocol analysis, system administration, programming, and cryptanalysis are all skills which have been required by prior CTF contests at DEF CON. There are two main styles of capture the flag competitions: attack/defense and jeopardy.
In an attack/defense style competition, each team is given a machine (or a small network) to defend on an isolated network. Teams are scored on both their success in defending their assigned machine and on their success in attacking other team's machines. Depending on the nature of the particular CTF game, teams may either be attempting to take an opponent's flag from their machine or teams may be attempting to plant their own flag on their opponent's machine.
Recently, an attack/defense style competition called MCTF held by Marjar University is coming, and there areN teams which participate in the competition. In the beginning, each team hasS points as initial score; during the competition, there are some checkpoints which will renew scores for all teams. The rules of the competition are as follows:
The score will be calculated at the checkpoints and then all attacks will be re-calculated. Edward is the organizer of the competition and he needs to write a program to display the scoreboard so the teams can see their scores instantly. But he doesn't know how to write. Please help him!
< h4< body="">Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains four integers N (2 <= N <= 100) - the number of teams,Q - the number of services (1 <= Q <= 10), S - the initial points (0 <=S <= 100000) and C - the number of checkpoints (1 <= C <= 100).
For each checkpoint, there are several parts:
[The No. of the attacker] [The No. of the defender] [The No. of the service]For example, "1 2 3" means the 1st team attacks the 2nd team in service 3 successfully. The No. of teams and services are indexed from 1. You should notice that duplicate messages are invalid because of the rules. Just ignore them.
Output
For each query L, output the score and the ranking of the Lth team. The relative error or absolute error of the score should be less than 10-5. The team with higher score gets higher rank; the teams with the same scores should have the same rank. It is guaranteed that the scores of any two teams are either the same or with a difference greater than 10-5.
< h4< body="">Sample Input
1 4 2 2500 5 0 1 1 1 1 1 1 1 1 4 1 2 3 4 2 1 2 1 3 2 1 1 1 1 1 1 1 1 1 4 1 2 3 4 1 1 2 2 1 1 1 1 1 1 1 0 4 1 2 3 4 0 0 0 0 0 0 0 0 0 4 1 2 3 4 0 1 1 1 1 1 1 1 1 2 1 4< h4< body="">
Sample Output
2500.00000000 1 2500.00000000 1 2500.00000000 1 2500.00000000 1 2501.50000000 1 2497.00000000 4 2501.50000000 1 2500.00000000 3 2505.50000000 1 2495.00000000 4 2502.50000000 2 2497.00000000 3 2499.50000000 1 2489.00000000 4 2496.50000000 2 2491.00000000 3 2499.50000000 1 2491.00000000 3
For C++ users, kindly use scanf to avoid TLE for huge inputs.
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstring> #include<algorithm> #include<set> #include<vector> using namespace std; typedef long long LL; struct Node { double sc; int k, rat; friend bool operator < (Node a, Node b) { if(a.sc >= b.sc) return true; else return false; } }; Node dt[10010], ans[10010]; int vis[110][110][110]; vector<int>vec[110][110]; struct Node1 { int b, c; }; Node1 vv[100010]; int sj[1010]; int main() { int T, N, Q, S, C; scanf("%d", &T); while(T--) { scanf("%d%d%d%d", &N, &Q, &S, &C); for(int i = 1; i <= N; i++) dt[i].k = i, dt[i].sc = S; while(C--) { memset(vis, 0, sizeof(vis)); for(int i = 0; i < 110; i++) for(int j = 0; j < 110; j++) vec[i][j].clear(); int tp = 0; int A; scanf("%d", &A); for(int j = 0; j < A; j++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); if(!vis[a][b][c]) { vis[a][b][c] = 1; if(vec[b][c].size() == 0) { vv[tp].b = b; vv[tp].c = c; tp++; } vec[b][c].push_back(a); } } for(int j = 0; j < tp; j++) { dt[vv[j].b].sc -= (N - 1); for(int i = 0; i < vec[vv[j].b][vv[j].c].size(); i++) { int a = vec[vv[j].b][vv[j].c][i]; dt[a].sc += 1.0*(N - 1)/vec[vv[j].b][vv[j].c].size(); } } for(int j = 1; j <= Q; j++) { int t = 0; for(int i = 1; i <= N; i++) { scanf("%d", sj + i); if(sj[i])t++; } for(int i = 1; i <= N; i++) { if(sj[i] == 0) { dt[i].sc -= (N - 1); for(int k = 1; k <= N; k++) { if(sj[k]) { dt[k].sc += 1.0*(N - 1)/t; } } } } } for(int i = 0; i <= 110; i++)ans[i] = dt[i]; sort(ans + 1, ans + N + 1); ans[1].rat = 1; for(int i = 2; i <= N; i++) { if(fabs(ans[i].sc - ans[i - 1].sc) <= 1e-6) { ans[i].rat = ans[i - 1].rat; } else ans[i].rat = i; } for(int i = 1; i <= N; i++) { dt[ans[i].k].rat = ans[i].rat; } int L; scanf("%d", &L); while(L--) { int x; scanf("%d", &x); for(int i = 1; i <= N; i++) { if(dt[i].k == x) { printf("%lf %d\n", dt[i].sc, dt[i].rat); break; } } } } } return 0; }
ZOJ - 3880
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
There is a popular multiplayer online battle arena game called Demacia of the Ancients. There are lots of professional teams playing this game. A team will be approved as LevelK if there are exact K team members whose match making ranking (MMR) is strictly greater than 6000.
You are given a list of teams. Please calculate the level of each team.
< h4< body="">Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer N (1 <= N <= 10) indicating the number of team members.
The second line contains N integers representing the MMR of each team member. All MMRs are non-negative integers less than or equal to 9999.
< h4< body="">Output
For each test case, output the level of the given team.
< h4< body="">Sample Input
3 5 7986 6984 6645 6200 6150 5 7401 7377 6900 6000 4300 3 800 600 200< h4< body="">
Sample Output
5 3 0
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstring> #include<algorithm> int main() { int t; scanf("%d",&t); while(t--) { int n; int ans=0; int x; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&x); if(x>6000) ans++; } printf("%d\n",ans); } return 0; }