Problem D. Nothing is Impossible
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 504 Accepted Submission(s): 302
Problem Description
m students, including Kazari, will take an exam tomorrow.
The paper consists of exactly n problems, the i-th problem contains ai correct answers and bi incorrect answers, i.e. the i-th problem contains ai+bi candidates in total.
Each student should choose exactly one candidate as answer for each problem. If the answer to a certain problem is correct, then the student will get one point. The student who gets the most points wins.
Students only know the structure of the paper, but they are able to talk with each other during the exam. They decide to choose a subset S of all n problems, and they will only be able to submit answers on these problems.
They want to know the maximum size of S that the winner among them will solve all the problems in S if they take the optimal strategy.
For sample 1, students can choose S={1},and we need at least 4 students to guarantee the winner solve the only problem.
For sample 2, students can choose S={1,2,3}, and we need at least 24 students to guarantee the winner solve these three problems, but if |S|=4, we need at least 96 students, which is more than 50.
Input
The first line of the input contains an integer T (1≤T≤100) denoting the number of test cases.
Each test case starts with two integers n,m (1≤n≤100,1≤m≤109), denoting the number of problems and the number of students. Each of next n lines contains two integers ai,bi (1≤bi≤100,ai=1), indicating the number of correct answers and the number of incorrect answers of the i-th problem.
Output
For each test case, print an integer denoting the maximum size of S.
Sample Input
2
3 5
1 3
1 3
1 3
5 50
1 1
1 3
1 2
1 3
1 5
Sample Output
1
3
Source
2018 Multi-University Training Contest 4
这道题在比赛的时候都改来改去,醉了,最后的解法就是找到答案数量少的,依次除以M取整,知道m小于一.
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 int a[105]; 5 int t; 6 int main(){ 7 scanf("%d",&t); 8 while(t--){ 9 int n,m; 10 memset(a,0,sizeof(a)); 11 scanf("%d%d",&n,&m); 12 for(int i=0;i<n;i++){ 13 int x,y; 14 scanf("%d%d",&x,&y); 15 a[i] = x+y; 16 } 17 sort(a,a+n); 18 int ans = 0; 19 for(int i=0;i<n&&m>=1;i++){ 20 m = m/a[i]; 21 ans++; 22 } 23 24 if(m>=1){ 25 cout<<ans<<endl; 26 }else 27 cout<<ans-1<<endl; 28 } 29 return 0; 30 }
Problem K. Expression in Memories
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4072 Accepted Submission(s): 864
Special Judge
Problem Description
Kazari remembered that she had an expression s0 before.
Definition of expression is given below in Backus–Naur form.
<expression> ::= <number> | <expression> <operator> <number>
<operator> ::= "+" | "*"
<number> ::= "0" | <non-zero-digit> <digits>
<digits> ::= "" | <digits> <digit>
<digit> ::= "0" | <non-zero-digit>
<non-zero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
For example, `1*1+1`, `0+8+17` are valid expressions, while +1+1, +1*+1, 01+001 are not.
Though s0 has been lost in the past few years, it is still in her memories.
She remembers several corresponding characters while others are represented as question marks.
Could you help Kazari to find a possible valid expression s0 according to her memories, represented as s, by replacing each question mark in s with a character in 0123456789+* ?
Input
The first line of the input contains an integer T denoting the number of test cases.
Each test case consists of one line with a string s (1≤|s|≤500,∑|s|≤105).
It is guaranteed that each character of s will be in 0123456789+*? .
Output
For each test case, print a string s0 representing a possible valid expression.
If there are multiple answers, print any of them.
If it is impossible to find such an expression, print IMPOSSIBLE.
Sample Input
5
?????
0+0+0
?+*??
?0+?0
?0+0?
Sample Output
11111
0+0+0
IMPOSSIBLE
10+10
IMPOSSIBLE
这道题其实没啥,就是判断能不能构成正确的式子.
?可以代替任何东西.
1 #include <iostream> 2 3 using namespace std; 4 5 int t; 6 int main(){ 7 scanf("%d",&t); 8 while(t--){ 9 string s,ss; 10 cin>>s; 11 bool prime = true; 12 int len = s.length(); 13 if(s[0]==‘*‘||s[0]==‘+‘||s[len-1]==‘*‘||s[len-1]==‘+‘){ 14 cout<<"IMPOSSIBLE"<<endl; 15 prime = false; 16 continue; 17 } 18 for(int i=0;i<len-1;i++){ 19 if(i==0){ 20 if(s[i]==‘0‘){ 21 if(s[i+1]>=‘0‘&&s[i+1]<=‘9‘){ 22 cout<<"IMPOSSIBLE"<<endl; 23 prime = false; 24 break; 25 }else{ 26 s[i+1] = s[i+1]==‘?‘?‘+‘:s[i+1]; 27 } 28 }else{ 29 s[i] = s[i]==‘?‘?‘1‘:s[i]; 30 } 31 }else{ 32 if(s[i]==‘?‘) 33 s[i] = ‘1‘; 34 if(s[i]>‘0‘&&s[i]<=‘9‘){ 35 s[i+1] = s[i+1]==‘?‘?‘1‘:s[i+1]; 36 }else if(s[i]==‘0‘){ 37 if(s[i-1]==‘*‘||s[i-1]==‘+‘){ 38 if(s[i+1]>=‘0‘&&s[i+1]<=‘9‘){ 39 cout<<"IMPOSSIBLE"<<endl; 40 prime = false; 41 break; 42 }else{ 43 s[i+1] = s[i+1]==‘?‘?‘+‘:s[i+1]; 44 } 45 }else{ 46 s[i+1] = s[i+1]==‘?‘?‘1‘:s[i+1]; 47 } 48 }else if(s[i]==‘+‘||s[i]==‘*‘){ 49 if(s[i+1]==‘+‘||s[i+1]==‘*‘){ 50 cout<<"IMPOSSIBLE"<<endl; 51 prime = false; 52 break; 53 }else{ 54 s[i+1] = s[i+1]==‘?‘?‘1‘:s[i+1]; 55 } 56 } 57 } 58 } 59 if(s[len-1]==‘*‘||s[len-1]==‘+‘){ 60 cout<<"IMPOSSIBLE"<<endl; 61 prime = false; 62 continue; 63 } 64 if(prime){ 65 cout<<s<<endl; 66 } 67 } 68 return 0; 69 }
Problem L. Graph Theory Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2408 Accepted Submission(s): 1054
Problem Description
There is a complete graph containing n vertices, the weight of the i-th vertex is wi.
The length of edge between vertex i and j (i≠j) is ⌊|wi−wj|−−−−−−−√⌋.
Calculate the length of the shortest path from 1 to n.
Input
The first line of the input contains an integer T (1≤T≤10) denoting the number of test cases.
Each test case starts with an integer n (1≤n≤105) denoting the number of vertices in the graph.
The second line contains n integers, the i-th integer denotes wi (1≤wi≤105).
Output
For each test case, print an integer denoting the length of the shortest path from 1 to n.
Sample Input
1
3
1 3 5
Sample Output
2
签到题.
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 int a[100005]; 5 int t; 6 int main(){ 7 cin>>t; 8 while(t--){ 9 int n; 10 cin>>n; 11 for(int i=0;i<n;i++){ 12 cin>>a[i]; 13 } 14 int ans = (int)sqrt(abs(a[0]-a[n-1])); 15 cout<<ans<<endl; 16 } 17 return 0; 18 }
原文地址:https://www.cnblogs.com/zllwxm123/p/9406810.html