A .Banana
Bananas are the favoured food of monkeys.
In the forest, there is a Banana Company that provides bananas from different places.
The company has two lists.
The first list records the types of bananas preferred by different monkeys, and the second one records the types of bananas from different places.
Now, the supplier wants to know, whether a monkey can accept at least one type of bananas from a place.
Remenber that, there could be more than one types of bananas from a place, and there also could be more than one types of bananas of a monkey’s preference.
Input Format
The first line contains an integer TT, indicating that there are TT test cases.
For each test case, the first line contains two integers NN and MM, representing the length of the first and the second lists respectively.
In the each line of following NN lines, two positive integers i, ji,j indicate that the ii-th monkey favours the jj-th type of banana.
In the each line of following MM lines, two positive integers j, kj,k indicate that the jj-th type of banana could be find in the kk-th place.
All integers of the input are less than or equal to 5050.
Output Format
For each test case, output all the pairs x, yx,y that the xx-the monkey can accept at least one type of bananas from the yy-th place.
These pairs should be outputted as ascending order. That is say that a pair of x, yx,y which owns a smaller xx should be output first.
If two pairs own the same xx, output the one who has a smaller yy first.
And there should be an empty line after each test case.
样例输入
1
6 4
1 1
1 2
2 1
2 3
3 3
4 1
1 1
1 3
2 2
3 3
样例输出
1 1
1 2
1 3
2 1
2 3
3 3
4 1
4 3
签到,写两个map记录每个产地有哪几种水果,每个猴子喜欢哪种水果,双重for一下,第三重用map迭代器迭代下各产地的各个水果种类是否能有对应猴子喜欢就行。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define LL long long 5 #define mod 1000000007 6 using namespace std; 7 map<int,bool>::iterator it; 8 int main() 9 { 10 int n,m,T,u,v; 11 scanf("%d",&T); 12 while(T--) 13 { 14 scanf("%d%d",&n,&m); 15 map<int,bool> a[60],b[60]; 16 for(int i=1;i<=n;i++) 17 { 18 scanf("%d%d",&u,&v); 19 a[u][v]=1; 20 } 21 for(int j=1;j<=m;j++) 22 { 23 scanf("%d%d",&u,&v); 24 b[v][u]=1; 25 } 26 for(int i=1;i<=50;i++) 27 { 28 for(int j=1;j<=50;j++) 29 { 30 for(it=b[j].begin();it!=b[j].end();it++) 31 { 32 if(a[i].find(it->first)!=a[i].end()) 33 { 34 printf("%d %d\n",i,j); 35 break; 36 } 37 } 38 } 39 } 40 printf("\n"); 41 } 42 return 0; 43 }
C.Coconut
Coconut is Captain Gangplank’s favourite fruit. That is why he needs to drink coconut juice from bb coconuts each day.
On his next trip, he would pass through NN citis.
His trip would begin in the 11-st city and end in the NN-th city.
The journey from the ii-th city to the (i+1)(i+1)-th city costs D_iD
?i
?? days.
Initially, there is no coconut on his ship. Fortunately, he could get supply of C_iC
?i
?? coconuts from the ii-th city.
Could you tell him, whether he could drink coconut juice every day during the trip no not?
Input Format
The first line contains an integer TT, indicating that there are TT test cases.
For each test case the first line contains two integers NN and bb as described above.
The second line contains NN integers C_1, C_2, \cdots, C_NC
?1
?? ,C
?2
?? ,?,C
?N
?? .
The third line contains N-1N?1 integers D_1, D_2, \cdots, D_{N-1}D
?1
?? ,D
?2
?? ,?,D
?N?1
?? .
All integers in the input are less than 10001000.
Output Format
For each case, output Yes if Captain Gangplank could drink coconut juice every day, and otherwise output No.
样例输入
2
4 1
3 2 1 4
1 2 3
4 2
2 4 6 8
3 2 1
样例输出
Yes
No
水题,for一遍就好了。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int sum[1005]; 5 6 int main() { 7 int n, b; 8 int t; 9 scanf("%d", &t); 10 while(t --) { 11 scanf("%d%d", &n, &b); 12 memset(sum, 0, sizeof(sum)); 13 for(int i = 1; i <= n; ++ i) { 14 int x; 15 scanf("%d", &x); 16 sum[i] = sum[i-1] + x; 17 } 18 int a = 0; 19 bool ok = true; 20 for(int i = 2; i <= n; ++ i) { 21 int x; 22 scanf("%d", &x); 23 a += x*b; 24 if(sum[i-1] < a) { 25 ok = false; 26 } 27 } 28 if(ok) { 29 puts("Yes"); 30 } 31 else { 32 puts("No"); 33 } 34 } 35 return 0; 36 }
E. Half-consecutive Numbers
emmm就是打个表的事情嘛~,如果嫌麻烦直接上eios233333。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define LL long long 5 #define mod 1000000007 6 using namespace std; 7 LL a[23]={ 0, 1, 8, 49, 288, 1681, 9800, 57121, 332928, 1940449, 11309768, 65918161, 384199200, 2239277041, 13051463048, 76069501249, 443365544448, 2584123765441, 15061377048200, 87784138523761, 511643454094368, 2982076586042449, 17380816062160328}; 8 int main() 9 { 10 int T; 11 LL n; 12 scanf("%d",&T); 13 for(int kase=1;kase<=T;kase++) 14 { 15 scanf("%lld",&n); 16 for(int i=0;i<23;i++) 17 if(a[i]>=n) 18 { 19 printf("Case #%d: %lld\n",kase,a[i]); 20 break; 21 } 22 } 23 return 0; 24 }