2018 Multi-University Training Contest 4

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

时间: 2024-10-05 03:00:13

2018 Multi-University Training Contest 4的相关文章

2018 Nowcoder Multi-University Training Contest 2

Practice Link A. run 题意: 白云每次可以移动\(1\)米或者\(k\)米,询问移动的米数在\([L, R]\)范围内的方案数有多少. 思路: \(dp[i][2]\)表示到第\(i\)米,是通过\(1\)米的方式过来的还是\(k\)米的方式过来的,递推即可. 代码: #include <bits/stdc++.h> using namespace std; #define N 100010 const int p = 1e9 + 7; int f[N][2], g[N];

2018 Nowcoder Multi-University Training Contest 1

Practice Link J. Different Integers 题意: 给出\(n\)个数,每次询问\((l_i, r_i)\),表示\(a_1, \cdots, a_i, a_j, \cdots, a_n\)中有多少个不同的数. 思路: 先分别离线求出\(a_1, \cdots a_i\)以及\(a_j, \cdots, a_n\)中有多少个不同的数. 再考虑有多少个数既在\([1, i]\)中也在\([j, n]\)中,再离线做一次. 考虑一个数第一次出现的时候,那么这个数下一次出现

2018 Nowcoder Multi-University Training Contest 5

Practice Link A. gpa 题意: 有\(n\)门课程,每门课程的学分为\(s_i\),绩点为\(c_i\),要求最多删除\(k\)门课程,使得gpa最高. gpa计算方式如下: \[ \begin{eqnarray*} gpa = \frac{\sum s_ic_i}{\sum s_i} \end{eqnarray*} \] 思路: 首先删去的课程越多,gpa肯定不会变得更差. 所以我们肯定是删去\(k\)门课程. 考虑二分答案,check的时候要满足: \[ \begin{eq

HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 5943    Accepted Submission(s): 2004 Problem Description Before

杭电2018多校第一场(2018 Multi-University Training Contest 1) 1001.Maximum Multiple (HDU6298)-数学思维题(脑子是个好东西,可惜我没有)

暑假杭电多校第一场,这一场是贪心场,很多贪心的题目,但是自己太菜,姿势挫死了,把自己都写吐了... 2018 Multi-University Training Contest 1 HDU6298.Maximum Multiple 题目意思就是给你一个n,找出来三个数x,y,z, 使得n=x+y+z,而且x,y,z都是n的因数,并且x*y*z为最大值,让你输出来x*y*z的最大值.如果没有满足条件的情况就输出-1. 由1=1/2+1/3+1/6=1/3+1/3+1/3=1/2+1/4+1/4,所

HDU 6396 Swordsman --------2018 Multi-University Training Contest 7 (模拟+读入挂)

原题地址: 打怪升级 一开始有N个怪物:主角有K个能力:只有K个能力都击败怪物才能斩杀怪物并获得K个能力的增值:问最多能杀几个怪物: 做法: 用优先队列把怪物能力装进去:能力小放前面: 最重要的是数据量要用读入挂才能过:(读入挂太神奇了!!) Swordsman Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2049    Acce

2018 Multi-University Training Contest 3

2018 Multi-University Training Contest 2 题解 A - Problem A. Ascending Rating 题目描述:给定一个序列,分别求出所有长度为\(m\)的区间的\(maxrating, count\),对于每个长度为\(m\)的区间,一开始\(maxrating=-1, count=0\),然后从左往右扫,扫到一个大于\(maxrating\)的值时,\(count+1, maxrating=\)那个数. solution 从左往右做,用单调队

2018 Multi-University Training Contest 1 Distinct Values 【贪心 + set】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5312    Accepted Submission(s): 1823 Problem Description Chiaki has an array of

2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1536    Accepted Submission(s): 830 Problem Description Ther