首页 > 代码库 > 2017-4-16-Train:Codeforces Beta Round #4 (Div. 2 Only)

2017-4-16-Train:Codeforces Beta Round #4 (Div. 2 Only)

反思:

我去确实很菜啊,写不动数据结构,写不动trick题,脑子转不动。

可能一直在写专题,都是不需要思考用什么方法的题目,所以都没有经过太多的思考。就像今天的DIV2.实话真的简单,但是我只有一题1A,其中B题没读到题目细节,还有D题没想到DP去做,而是直接写模拟了。唉,说多了都是泪,加油训练吧

A. Watermelon(水题)

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

Pete and Billy are great fans of even numbers, that‘s why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that‘s why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

Input

The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

Output

Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.

Examples

input

8

output

YES

Note

For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

Means:

问你能不能把这个重量的西瓜分成两份质量为偶数的

Solve:

就是判断一个数是不是偶数,然后特判下2,如果是2的话,分不了两个偶数

Code:

技术分享
 1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5     int w; 6     scanf("%d" , &w); 7     if(w & 1 || w < 4) 8     { 9         puts("NO");10     }11     else12         puts("YES");13 }
View Code

B. Before an Exam(Trick + 模拟)

Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter‘s strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.

So, today is the day when Peter‘s parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with dnumbers, where each number sсhedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.

Input

The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbersminTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.

Output

In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents‘ instructions; or print NO in the unique line. If there are many solutions, print any of them.

Examples

input

1 48
5 7

output

NO

input

2 5
0 1
3 5

output

YES
1 4

Means:

给出n天的学习时间上下界,,问你这些天每天最少的学习时间是多少,使得总学习时间等于给出的时间

Solve:

一开始没有看出每天最少学习时间,用的DFS去做的,果断挂,然后看了题解,知道每次最少时间,那么就直接模拟咯

Code:

技术分享
 1 #include <bits/stdc++.h> 2 using namespace std; 3 static const int MAXN = 33; 4 int d , t; 5 int mi[MAXN] , mx[MAXN]; 6 int main() 7 { 8     scanf("%d%d" , &d , &t); 9     for(int i = 0 ; i < d ; ++i)10     {11         scanf("%d%d" , &mi[i] , &mx[i]);12         t -= mi[i];13     }14     if(t < 0)15     {16         puts("NO");17         return 0;18     }19     for(int i = 0 ; i < d ; ++i)20     {21         int tp = mx[i] - mi[i];22         if(tp > t)23         {24             tp = t;25         }26         mi[i] += tp;27         t -= tp;28         if(t == 0)29             break;30     }31     if(t == 0)32     {33         puts("YES");34         for(int i = 0 ; i < d ; ++i)35             printf("%d " , mi[i]);36     }37     else38         puts("NO");39 }
View Code

C. Registration system(模拟 + 数据结构)

A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that‘s why they ask you to help. You‘re suggested to implement the prototype of site registration system. The system should work on the following principle.

Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name(name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database.

Input

The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.

Output

Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.

Examples

input

4
abacaba
acaba
abacaba
acab

output

OK
OK
abacaba1
OK

input

6
first
first
second
second
third
third

output

OK
first1
OK
second1
OK
third1

Means:

用户注册,如果用户输入的名字没有出现过,输出OK,否则输出用户名+数字,数字为前面出现过的次数

Solve:

水题,我是直接MAP怼过去的

Code:

技术分享
 1 #include <bits/stdc++.h> 2 using namespace std; 3 map <string , int> mmp; 4 int n; 5 int main() 6 { 7     string data; 8     scanf("%d" , &n); 9     for(int i = 0 ; i < n ; ++i)10     {11         cin >> data;12         if(!mmp[data])13         {14             printf("OK\n");15             mmp[data] = 1;16         }17         else18         {19             cout << data;20             printf("%d\n" , mmp[data]);21             ++mmp[data];22         }23     }24 }
View Code

D. Mysterious Present(DP:LIS)

Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1,  a2,  ...,  an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i  -  1)-th envelope respectively. Chain size is the number of envelopes in the chain.

Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he‘ll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It‘s forbidden to turn the card and the envelopes.

Peter has very many envelopes and very little time, this hard task is entrusted to you.

Input

The first line contains integers nwh (1  ≤ n ≤ 5000, 1 ≤ w,  h  ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi,  hi ≤ 106).

Output

In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers.

If the card does not fit into any of the envelopes, print number 0 in the single line.

Examples

input

2 1 1
2 2
2 2

output

1
1

input

3 3 3
5 4
12 11
9 8

output

3
1 3 2

Means:

题意就是套信封,就是从里往外卡片塞信封里,信封塞信封里,要求信封严格大于信封,信封严格大于卡片,问你最多能嵌套多少个,以及从里往外的信封编号。

Solve:

排序后DPLIS,我一开始大力模拟,WA,只能说明我好菜

Code:

技术分享
 1 #include <bits/stdc++.h> 2 using namespace std; 3 static const int MAXN = 5e3 + 10; 4 int n , ew , eh; 5 int out[MAXN]; 6 int dp[MAXN]; 7 struct Node 8 { 9     int w , h , id;10 };11 vector <Node> tp;12 void Print(int pos)13 {14     if(pos == -1)15         return ;16     Print(out[pos]);17     printf("%d " , tp[pos].id);18 }19 inline bool cmp(Node a , Node b)20 {21     return (a.w == b.w) ? a.h < b.h : a.w < b.w;22 }23 int main(int argc, char const *argv[])24 {25     int a , b;26     scanf("%d%d%d" , &n , &ew , &eh);27     for(int i = 0 ; i < n ; ++i)28     {29         scanf("%d%d" , &a , &b);30         if(a > ew && b > eh)31             tp.push_back({a , b , i + 1});32     }33     sort(tp.begin() , tp.end() , cmp);34     memset(out , -1 , sizeof(out));35     int si = tp.size();36     for(int i = 0 ; i <= si ; ++i) dp[i] = 1;37     for(int i = 1 ; i < si ; ++i)38     {39         for(int j = 0 ; j < i ; ++j)40         {41             if(tp[i].w > tp[j].w && tp[i].h > tp[j].h)42             {43                 if(dp[i] <= dp[j] + 1)44                 {45                     dp[i] = dp[j] + 1;46                     out[i] = j;47                 }48             }49         }50     }51     int ans = 0 , pos = -1;52     for(int i = 0 ; i < si ; ++i)53     {54         if(dp[i] > ans)55         {56             ans = dp[i];57             pos = i;58         }59     }60     printf("%d\n" , ans);61     Print(pos);62     return 0;63 }
View Code

 

2017-4-16-Train:Codeforces Beta Round #4 (Div. 2 Only)