A - Cooking Competition
"Miss Kobayashi's Dragon Maid" is a Japanese manga series written and illustrated by Coolkyoushinja. An anime television series produced by Kyoto Animation aired in Japan between January and April 2017.
In episode 8, two main characters, Kobayashi and Tohru, challenged each other to a cook-off to decide who would make a lunchbox for Kanna's field trip. In order to decide who is the winner, they asked n people to taste their food, and changed their scores according to the feedback given by those people.
There are only four types of feedback. The types of feedback and the changes of score are given in the following table.
Type | Feedback | Score Change (Kobayashi) | Score Change (Tohru) |
---|---|---|---|
1 | Kobayashi cooks better | +1 | 0 |
2 | Tohru cooks better | 0 | +1 |
3 | Both of them are good at cooking | +1 | +1 |
4 | Both of them are bad at cooking | -1 | -1 |
Given the types of the feedback of these n people, can you find out the winner of the cooking competition (given that the initial score of Kobayashi and Tohru are both 0)?
InputThere are multiple test cases. The first line of input contains an integer T (1 ≤ T≤ 100), indicating the number of test cases. For each test case:
The first line contains an integer n (1 ≤ n ≤ 20), its meaning is shown above.
The next line contains n integers a1, a2, ... , an (1 ≤ ai ≤ 4), indicating the types of the feedback given by these n people.
<h4< dd="">OutputFor each test case output one line. If Kobayashi gets a higher score, output "Kobayashi" (without the quotes). If Tohru gets a higher score, output "Tohru" (without the quotes). If Kobayashi's score is equal to that of Tohru's, output "Draw" (without the quotes).
<h4< dd="">Sample Input2 3 1 2 1 2 3 4<h4< dd="">Sample Output
Kobayashi Draw
代码:
#include<bits/stdc++.h> using namespace std; int T; int main() { scanf("%d", &T); while(T --) { int N; int a = 0, b = 0; scanf("%d", &N); for(int i = 0; i < N; i ++) { int x; scanf("%d", &x); if(x == 1) a ++; else if(x == 2) b ++; } if(a > b) printf("Kobayashi "); else if(a == b) printf("Draw "); else printf("Tohru "); } }
B - Problem Preparation
It's time to prepare the problems for the 14th Zhejiang Provincial Collegiate Programming Contest! Almost all members of Zhejiang University programming contest problem setter team brainstorm and code day and night to catch the deadline, and empty bottles of Marjar Cola litter the floor almost everywhere!
To make matters worse, one of the team member fell ill just before the deadline. So you, a brilliant student, are found by the team leader Dai to help the team check the problems' arrangement.
Now you are given the difficulty score of all problems. Dai introduces you the rules of the arrangement:
- The number of problems should lie between 10 and 13 (both inclusive).
- The difficulty scores of the easiest problems (that is to say, the problems with the smallest difficulty scores) should be equal to 1.
- At least two problems should have their difficulty scores equal to 1.
- After sorting the problems by their difficulty scores in ascending order, the absolute value of the difference of the difficulty scores between two neighboring problems should be no larger than 2. BUT, if one of the two neighboring problems is the hardest problem, there is no limitation about the difference of the difficulty scores between them. The hardest problem is the problem with the largest difficulty score. It's guaranteed that there is exactly one hardest problem.
The team members have given you lots of possible arrangements. Please check whether these arrangements obey the rules or not.
Input
There are multiple test cases. The first line of the input is an integer T (1 ≤ T≤ 104), indicating the number of test cases. Then T test cases follow.
The first line of each test case contains one integer n (1 ≤ n ≤ 100), indicating the number of problems.
The next line contains n integers s1, s2, ... , sn (-1000 ≤ si ≤ 1000), indicating the difficulty score of each problem.
We kindly remind you that this problem contains large I/O file, so it's recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.
<h4< dd="">Output
For each test case, output "Yes" (without the quotes) if the arrangement follows the rules, otherwise output "No" (without the quotes).
<h4< dd="">Sample Input
8 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 999 1 1 2 3 4 5 6 7 8 9 11 999 1 3 5 7 9 11 13 17 19 21 10 15 1 13 17 1 7 9 5 3 11 13 1 1 1 1 1 1 1 1 1 1 1 1 2 10 2 3 4 5 6 7 8 9 10 11 10 15 1 13 3 6 5 4 7 1 14
<h4< dd="">Sample Output
No No Yes No Yes Yes No No
<h4< dd="">Hint
The first arrangement has 9 problems only, which violates the first rule.
Only one problem in the second and the fourth arrangement has a difficulty score of 1, which violates the third rule.
The easiest problem in the seventh arrangement is a problem with a difficulty score of 2, which violates the second rule.
After sorting the problems of the eighth arrangement by their difficulty scores in ascending order, we can get the sequence 1, 1, 3, 4, 5, 6, 7, 13, 14, 15. We can easily discover that |13 - 7| = 6 > 2. As the problem with a difficulty score of 13 is not the hardest problem (the hardest problem in this arrangement is the problem with a difficulty score of 15), it violates the fourth rule.
代码:
#include<bits/stdc++.h> using namespace std; int T; int a[1005]; int main() { scanf("%d", &T); while(T --) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } sort(a+1,a+n+1); int flag=0,num=0; for(int i=1;i<=n;i++) { if(a[i]==1) num++; } for(int i=2;i<=n-1;i++) { if(a[i]-a[i-1]>2) flag=1; } if(num>=2&&!flag&&n>=10&&n<=13&&a[1]==1) printf("Yes "); else printf("No "); } return 0; }
C - What Kind of Friends Are You?
Japari Park is a large zoo home to extant species, endangered species, extinct species, cryptids and some legendary creatures. Due to a mysterious substance known as Sandstar, all the animals have become anthropomorphized into girls known as Friends.
Kaban is a young girl who finds herself in Japari Park with no memory of who she was or where she came from. Shy yet resourceful, she travels through Japari Park along with Serval to find out her identity while encountering more Friends along the way, and eventually discovers that she is a human.
However, Kaban soon finds that it's also important to identify other Friends. Her friend, Serval, enlightens Kaban that she can use some questions whose expected answers are either "yes" or "no" to identitfy a kind of Friends.
To be more specific, there are n Friends need to be identified. Kaban will ask each of them q same questions and collect their answers. For each question, she also gets a full list of animals' names that will give a "yes" answer to that question (and those animals who are not in the list will give a "no" answer to that question), so it's possible to determine the name of a Friends by combining the answers and the lists together.
But the work is too heavy for Kaban. Can you help her to finish it?
Input
There are multiple test cases. The first line of the input is an integer T (1 ≤ T≤ 100), indicating the number of test cases. Then T test cases follow.
The first line of each test case contains two integers n (1 ≤ n ≤ 100) and q (1 ≤ q ≤ 21), indicating the number of Friends need to be identified and the number of questions.
The next line contains an integer c (1 ≤ c ≤ 200) followed by c strings p1, p2, ... , pc (1 ≤ |pi| ≤ 20), indicating all known names of Friends.
For the next q lines, the i-th line contains an integer mi (0 ≤ mi ≤ c) followed by mi strings si, 1, si, 2, ... , si, mi (1 ≤ |si, j| ≤ 20), indicating the number of Friends and their names, who will give a "yes" answer to the i-th question. It's guaranteed that all the names appear in the known names of Friends.
For the following n lines, the i-th line contains q integers ai, 1, ai, 2, ... , ai, q(0 ≤ ai, j ≤ 1), indicating the answer (0 means "no", and 1 means "yes") to the j-th question given by the i-th Friends need to be identified.
It's guaranteed that all the names in the input consist of only uppercase and lowercase English letters.
<h4< dd="">Output
For each test case output n lines. If Kaban can determine the name of the i-th Friends need to be identified, print the name on the i-th line. Otherwise, print "Let's go to the library!!" (without quotes) on the i-th line instead.
<h4< dd="">Sample Input
2 3 4 5 Serval Raccoon Fennec Alpaca Moose 4 Serval Raccoon Alpaca Moose 1 Serval 1 Fennec 1 Serval 1 1 0 1 0 0 0 0 1 0 0 0 5 5 11 A B C D E F G H I J K 3 A B K 4 A B D E 5 A B K D E 10 A B K D E F G H I J 4 B D E K 0 0 1 1 1 1 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1
<h4< dd="">Sample Output
Serval Let's go to the library!! Let's go to the library!! Let's go to the library!! Let's go to the library!! B Let's go to the library!! K
<h4< dd="">Hint
The explanation for the first sample test case is given as follows:
As Serval is the only known animal who gives a "yes" answer to the 1st, 2nd and 4th question, and gives a "no" answer to the 3rd question, we output "Serval" (without quotes) on the first line.
As no animal is known to give a "no" answer to all the questions, we output "Let's go to the library!!" (without quotes) on the second line.
Both Alpaca and Moose give a "yes" answer to the 1st question, and a "no" answer to the 2nd, 3rd and 4th question. So we can't determine the name of the third Friendsneed to be identified, and output "Let's go to the library!!" (without quotes) on the third line.
代码:
#include <bits/stdc++.h> using namespace std; const int maxn = 550; int T; map<string, int> pos; map<int, string> id; int mp[maxn]; int num[maxn][maxn]; int Pow(int a, int b) { int ans = 1; while(b) { if(b % 2) { ans *= a; b --; } else { a *= a; b /= 2; } } return ans; } int main() { scanf("%d", &T); while(T --) { memset(mp, 0, sizeof(mp)); memset(num, 0, sizeof(num)); pos.clear(); id.clear(); int N, Q, K; scanf("%d%d", &N, &Q); scanf("%d", &K); for(int i = 1; i <= K; i ++) { string s; cin >> s; pos[s] = i; id[i] = s; mp[pos[s]] = 0; } for(int q = 1; q <= Q; q ++) { int x; scanf("%d", &x); for(int i = 0; i < x; i ++) { string op; cin >> op; mp[pos[op]] += (1<<(Q - q)); } } for(int i = 1; i <= N; i ++) { int sum = 0; for(int j = 1; j <= Q; j ++) { scanf("%d", &num[i][j]); if(num[i][j] == 1) sum += (1<<(Q - j)); } //cout << sum << endl; int temp = -1, cnt = 0; for(int j = 1; j <= K; j ++) { if(mp[j] == sum) { temp = j; cnt ++; } } if(cnt == 0 || cnt > 1) printf("Let's go to the library!! "); else cout << id[temp] << endl; } } return 0; }
D - Let's Chat
ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technology Company. To attract more users, Edward, the boss of Marjar Company, has recently added a new feature to the software. The new feature can be described as follows:
If two users, A and B, have been sending messages to each other on the last mconsecutive days, the "friendship point" between them will be increased by 1 point.
More formally, if user A sent messages to user B on each day between the (i - m + 1)-th day and the i-th day (both inclusive), and user B also sent messages to user A on each day between the (i - m + 1)-th day and the i-th day (also both inclusive), the "friendship point" between A and B will be increased by 1 at the end of the i-th day.
Given the chatting logs of two users A and B during n consecutive days, what's the number of the friendship points between them at the end of the n-th day (given that the initial friendship point between them is 0)?
Input
There are multiple test cases. The first line of input contains an integer T (1 ≤ T≤ 10), indicating the number of test cases. For each test case:
The first line contains 4 integers n (1 ≤ n ≤ 109), m (1 ≤ m ≤ n), x and y (1 ≤ x, y ≤ 100). The meanings of n and m are described above, while x indicates the number of chatting logs about the messages sent by A to B, and y indicates the number of chatting logs about the messages sent by B to A.
For the following x lines, the i-th line contains 2 integers la, i and ra, i (1 ≤ la,i ≤ ra, i ≤ n), indicating that A sent messages to B on each day between the la, i-th day and the ra, i-th day (both inclusive).
For the following y lines, the i-th line contains 2 integers lb, i and rb, i (1 ≤ lb,i ≤ rb, i ≤ n), indicating that B sent messages to A on each day between the lb, i-th day and the rb, i-th day (both inclusive).
It is guaranteed that for all 1 ≤ i < x, ra, i + 1 < la, i + 1 and for all 1 ≤ i < y, rb, i + 1 < lb, i + 1.
<h4< dd="">Output
For each test case, output one line containing one integer, indicating the number of friendship points between A and B at the end of the n-th day.
<h4< dd="">Sample Input
2 10 3 3 2 1 3 5 8 10 10 1 8 10 10 5 3 1 1 1 2 4 5
<h4< dd="">Sample Output
3 0
<h4< dd="">Hint
For the first test case, user A and user B send messages to each other on the 1st, 2nd, 3rd, 5th, 6th, 7th, 8th and 10th day. As m = 3, the friendship points between them will be increased by 1 at the end of the 3rd, 7th and 8th day. So the answer is 3.
代码:
#include<bits/stdc++.h> using namespace std; const int maxn=105; int cal(int l1,int r1,int l2,int r2) { if(r2<r1) { swap(r1,r2); swap(l1,l2); } if(l1>=l2) return r1-l1+1; if(r1<l2) return 0; return r1-l2+1; } int la[maxn],ra[maxn],lb[maxn],rb[maxn]; int main() { int T;scanf("%d",&T); while(T--) { int n,m,x,y;scanf("%d%d%d%d",&n,&m,&x,&y); int len1=0,len2=0; for(int i=1;i<=x;i++) { int l,r; scanf("%d%d",&l,&r); if(len1==0||l-1>ra[len1]) la[++len1]=l,ra[len1]=r; else ra[len1]=r; } for(int i=1;i<=y;i++) { int l,r; scanf("%d%d",&l,&r); if(len2==0||l-1>rb[len2]) lb[++len2]=l,rb[len2]=r; else rb[len2]=r; } int ans=0; for(int i=1;i<=len1;i++) { for(int j=1;j<=len2;j++) { int d=cal(la[i],ra[i],lb[j],rb[j]); if(d>=m) ans+=d-m+1; } } printf("%d ",ans); } }
E - Seven Segment Display
A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven segment displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information.
Edward, a student in Marjar University, is studying the course "Logic and Computer Design Fundamentals" this semester. He bought an eight-digit seven segment display component to make a hexadecimal counter for his course project.
In order to display a hexadecimal number, the seven segment display component needs to consume some electrical energy. The total energy cost for display a hexadecimal number on the component is the sum of the energy cost for displaying each digit of the number. Edward found the following table on the Internet, which describes the energy cost for display each kind of digit.
|
|
|
For example, in order to display the hexadecimal number "5A8BEF67" on the component for one second, 5 + 6 + 7 + 5 + 5 + 4 + 6 + 3 = 41 units of energy will be consumed.
Edward's hexadecimal counter works as follows:
- The counter will only work for n seconds. After n seconds the counter will stop displaying.
- At the beginning of the 1st second, the counter will begin to display a previously configured eight-digit hexadecimal number m.
- At the end of the i-th second (1 ≤ i < n), the number displayed will be increased by 1. If the number displayed will be larger than the hexadecimal number "FFFFFFFF" after increasing, the counter will set the number to 0 and continue displaying.
Given n and m, Edward is interested in the total units of energy consumed by the seven segment display component. Can you help him by working out this problem?
Input
There are multiple test cases. The first line of input contains an integer T (1 ≤ T≤ 105), indicating the number of test cases. For each test case:
The first and only line contains an integer n (1 ≤ n ≤ 109) and a capitalized eight-digit hexadecimal number m (00000000 ≤ m ≤ FFFFFFFF), their meanings are described above.
We kindly remind you that this problem contains large I/O file, so it's recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.
<h4< dd="">Output
For each test case output one line, indicating the total units of energy consumed by the eight-digit seven segment display component.
<h4< dd="">Sample Input
3 5 89ABCDEF 3 FFFFFFFF 7 00000000
<h4< dd="">Sample Output
208 124 327
<h4< dd="">Hint
For the first test case, the counter will display 5 hexadecimal numbers (89ABCDEF, 89ABCDF0, 89ABCDF1, 89ABCDF2, 89ABCDF3) in 5 seconds. The total units of energy cost is (7 + 6 + 6 + 5 + 4 + 5 + 5 + 4) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 6) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 2) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 5) + (7 + 6 + 6 + 5 + 4 + 5 + 4 + 5) = 208.
For the second test case, the counter will display 3 hexadecimal numbers (FFFFFFFF, 00000000, 00000001) in 3 seconds. The total units of energy cost is (4 + 4 + 4 + 4 + 4 + 4 + 4 + 4) + (6 + 6 + 6 + 6 + 6 + 6 + 6 + 6) + (6 + 6 + 6 + 6 + 6 + 6 + 6 + 2) = 124.
代码:
#include<bits/stdc++.h> using namespace std; #define ll long long struct node { ll val,num; }dp[22]; int rev[22]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4}; int get_id(char x) { if(x>='A'&&x<='F') return 10+x-'A'; else return x-'0'; } int bit[22]; node dfs(int len,int flag) { if(len==0) { node ans;ans.val=0;ans.num=1; return ans; } if(!flag&&dp[len].num!=-1) return dp[len]; int limit=flag?bit[len]:15; node r;r.val=r.num=0; for(int i=0;i<=limit;i++) { node e=dfs(len-1,flag&&i==limit); r.val=r.val+e.val+rev[i]*e.num; r.num+=e.num; } if(!flag) dp[len]=r; return r; } ll work(ll x) { for(int i=1;i<=8;i++,x/=16) bit[i]=x%16; ll tmp=dfs(8,1).val; return tmp; } ll cal(ll l,ll r) { ll cnt=0; cnt+=work(r); cnt-=work(l); for(int i=1;i<=8;i++,l/=16) cnt+=rev[l%16]; return cnt; } int main() { for(int i=0;i<22;i++) { dp[i].num=-1; dp[i].val=0; } int T;scanf("%d",&T); ll limit=0; for(int i=1;i<=8;i++) limit=limit*16+15; while(T--) { int n;char t[12]; scanf("%d%s",&n,t+1); ll tmp=0; for(int i=1;i<=8;i++) tmp=tmp*16+get_id(t[i]); ll ans=0,l=tmp,r=tmp+n-1; if(r<=limit) { ans=cal(l,r); } else { ans=cal(l,limit)+cal(0,r-limit-1); } printf("%lld ",ans); } return 0; }
F - Heap Partition
A sequence S = {s1, s2, ..., sn} is called heapable if there exists a binary tree Twith n nodes such that every node is labelled with exactly one element from the sequence S, and for every non-root node si and its parent sj, sj ≤ si and j < ihold. Each element in sequence S can be used to label a node in tree T only once.
Chiaki has a sequence a1, a2, ..., an, she would like to decompose it into a minimum number of heapable subsequences.
Note that a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
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 contain an integer n (1 ≤ n ≤ 105) — the length of the sequence.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n).
It is guaranteed that the sum of all n does not exceed 2 × 106.
<h4< dd="">Output
For each test case, output an integer m denoting the minimum number of heapable subsequences in the first line. For the next m lines, first output an integer Ci, indicating the length of the subsequence. Then output Ci integers Pi1, Pi2, ..., PiCiin increasing order on the same line, where Pij means the index of the j-th element of the i-th subsequence in the original sequence.
<h4< dd="">Sample Input
4 4 1 2 3 4 4 2 4 3 1 4 1 1 1 1 5 3 2 1 4 1
<h4< dd="">Sample Output
1 4 1 2 3 4 2 3 1 2 3 1 4 1 4 1 2 3 4 3 2 1 4 1 2 2 3 5
代码:
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; vector<int>P[maxn]; int n,a[maxn],tz[maxn]; multiset<int>s; vector<int>G[maxn],ans[maxn]; int vis[maxn],is[maxn]; void dfs(int v,int fa,int len) { ans[len].push_back(v); is[v]=1; for(int i=G[v].size()-1;i>=0;i--) { int u=G[v][i]; if(u==fa) continue; dfs(u,v,len); } } int main() { int T;scanf("%d",&T); while(T--) { int n;scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { multiset<int>::iterator it=s.lower_bound(-a[i]); if(it!=s.end()) { int v=*it; v=-v; int u=P[v][tz[v]]; G[u].push_back(i); G[i].push_back(u); vis[u]--; if(vis[u]==0) { tz[v]++; s.erase(s.find(*it)); } } vis[i]=2; s.insert(-a[i]); P[a[i]].push_back(i); } int len=0; for(int i=1;i<=n;i++) { if(!is[i]) { dfs(i,0,len); len++; } } printf("%d ",len); for(int i=0;i<len;i++) { sort(ans[i].begin(),ans[i].end()); int sz=ans[i].size(); printf("%d",sz); for(int j=0;j<sz;j++) printf(" %d",ans[i][j]); printf(" "); } for(int i=0;i<=n;i++) { P[i].clear(); G[i].clear(); ans[i].clear(); vis[i]=is[i]=tz[i]=0; } s.clear(); } }
今天下午的训练赛 可惜 H 感觉是会的但是没写出来 难过
百香果圆梦