周赛题 (2015年浙江省赛)
来源:互联网 发布:武汉网络中控机 编辑:程序博客网 时间:2024/05/28 05:18
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 integersAi (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
352 2 2 1 151 1 2 2 31998< h4< body="">
Sample Output
2Nobody998
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");}elseprintf("%d\n", ans);}return 0;}
ZOJ - 3870
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 andB 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. Theith 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
231 2 351 2 3 4 5< h4< body="">
Sample Output
16
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
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
351 2 3 4 532 3 342 3 3 2< h4< body="">
Sample Output
1052138
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
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 andD 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
21 3 2Fresh_Cucumber 4Chow_Mein 5Rice_Served_with_Duck_Leg 12Fried_Vermicelli 7Steamed_Dumpling 3Steamed_Stuffed_Bun 42 3 1Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33West_Lake_Water_Shield_Soup 36DongPo's_Braised_Pork 54West_Lake_Fish_in_Vinegar 48Longjing_Shrimp 188DongPo's_Crisp 18< h4< body="">
Sample Output
15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun108 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
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?
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, there is an integery (1928 <=y <= 9999) in one line, indicating the year of Edward's query.
Output
For each case, print the number of days of the continuous vacation in that year.
Sample Input
3201520162017
Output
569
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;elsea[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");elseprintf("5\n");}return 0;}
ZOJ - 3878
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:
< h4< body="">
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;doeNfk Gq.d slpt a X,dokt vdtnsaoheKjd yspps,glu pgld; aod yso kd;kgluZ1234567890`~!@#$%^&*()}"']_+-=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`~!@#$%^&*()+_-={}[]:"'<>,.?/\|ABCDEFuvwxyzAXJE>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
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:
- If a team has been attacked for a service P, they will lose N - 1 points. The lost points will be split equally and be added to the team(s) which attacks successfully. For example, there are 4 teams and Team A has been attacked by Team B and Team C, so Team A will lose 3 points, while Team B and Team C each will get 1.5 points.
- If a team cannot maintain their service well, they will lose N - 1 points, which will be split equally too and be added to the team(s) which maintains the service well.
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) andC - the number of checkpoints (1 <= C <= 100).
For each checkpoint, there are several parts:
- The first line contains an integer A - the number of the successful attacks. ThenA lines follow and each line contains a message:
[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. - Then there are Q lines and each line contains N integers. Thejth number of theith line indicating thejth team's maintaining status of theith service, where 1 means well and 0 means not well.
- Finally there is an integer U (0 <= U <= 100), which describing the number of the queries. The following line containsU integers, which means Edward wants to know the score and the ranking of these teams.
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
14 2 2500 501 1 1 11 1 1 141 2 3 421 2 13 2 11 1 1 11 1 1 141 2 3 411 2 21 1 1 11 1 1 041 2 3 400 0 0 00 0 0 041 2 3 401 1 1 11 1 1 121 4< h4< body="">
Sample Output
2500.00000000 12500.00000000 12500.00000000 12500.00000000 12501.50000000 12497.00000000 42501.50000000 12500.00000000 32505.50000000 12495.00000000 42502.50000000 22497.00000000 32499.50000000 12489.00000000 42496.50000000 22491.00000000 32499.50000000 12491.00000000 3
Hint
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
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 exactK 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
357986 6984 6645 6200 615057401 7377 6900 6000 43003800 600 200< h4< body="">
Sample Output
530
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;}
- 周赛题 (2015年浙江省赛)
- 2015年浙江省赛
- 2015年浙江省赛总结
- 2015年浙江省省赛赛后总结
- 2015浙江省赛
- 2016年浙江省赛(模拟题)
- ZOJ 3870:Team Formation (浙江省赛2015)(二进制操作)
- 数学题ZOJ3870 Team Formation(2015浙江省赛)
- 2015 浙江省赛 Team Formation (思维题)
- 2015 浙江省赛 Beauty of Array (思维题)
- 浙江省赛
- ZOJ3879:Capture the Flag(浙江省赛2015)
- ZOJ3876:May Day Holiday(浙江省赛2015)
- ZOJ3875:Lunch Time(浙江省赛2015)
- ZOJ3872:Beauty of Array(浙江省赛2015)
- ZOJ3870:Team Formation(浙江省赛2015)
- ZOJ3869:Ace of Aces(浙江省赛2015)
- 浙江省赛 2015 -> A.Ace of Aces
- 移动开发入门指南
- 新手在windows7下安装ubuntu15.10
- 如何用phtoshop cs6 切图
- 异常 2 problemscvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be foun
- setup django 4 test
- 周赛题 (2015年浙江省赛)
- Chaikin细分曲线
- 层次遍历二叉树
- 重载内核全程分析笔记
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版本强势发布
- DP 动态规划 Problem M 1013 母牛问题
- iOS - 加速计程序的开发
- 图论判环模板
- innerHTML、getElementsByName()、getElementsByTagName()