A. Chess Tourney
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Berland annual chess tournament is coming!

Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.

Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins.

Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.

After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.

Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardlessof the results of the drawing?

Input

The first line contains one integer n (1 ≤ n ≤ 100).

The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).

Output

If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".

题意:给2*n个选手拥有不用的实力,实力高的肯定能赢实力低的,相同实力随机赢,问能否把他们分成两组使一组无论怎么匹配打都能赢?

题解:sort()一下,然判断那组是否最小值比另外一组最小值大

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define ll long long
  6. using namespace std;
  7. const int maxn=2e2+;
  8. const ll inf=0x4f4f4f4f4f;
  9. int n,k;
  10. int a[maxn];
  11. int main()
  12. {
  13. scanf("%d",&n);
  14. for(int i=;i<*n;i++)
  15. {
  16. scanf("%d",&a[i]);
  17. }
  18. sort(a,a+*n);
  19. if(a[n]>a[n-])printf("YES\n");
  20. else printf("NO\n");
  21. }
B. Luba And The Ticket
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.

The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.

Input

You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.

Output

Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.

Examples
input
  1. 000000
output
  1. 0
input
  1. 123456
output
  1. 2
input
  1. 111000
output
  1. 1
Note

In the first example the ticket is already lucky, so the answer is 0.

In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.

In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.

题意:当前面三个数字之和等于后面三个数字则称这六个数字组成的是幸运数,给六个数字问最改动几个数字使得这六个数成幸运数

题解:把前三个数字和后三个之和求出,相同则为0,不同就判断两个之差能否通过改变一个数字变的(让最小的变大或者最大变小),如果一个不行然后同理判改变两个。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define ll long long
  6. using namespace std;
  7. const int maxn=2e2+;
  8. const ll inf=0x4f4f4f4f4f;
  9. int n,k;
  10. char b[];
  11. int a[];
  12. int main()
  13. {
  14. scanf("%s",b);
  15. int tmp1=,tmp2=;
  16. for(int i=;i<;i++)
  17. {
  18. a[i]=b[i]-'';
  19. if(i<)tmp1+=a[i];
  20. else tmp2+=a[i];
  21. }
  22. sort(a+,a+);
  23. sort(a+,a+);
  24. //for(int i=0;i<6;i++)cout<<a[i]<<endl;
  25. if(tmp1==tmp2)
  26. {
  27. printf("0\n");
  28. }
  29. else if(tmp1<tmp2)
  30. {
  31. if(-a[]>=tmp2-tmp1||a[]>=tmp2-tmp1)
  32. {
  33. printf("1\n");
  34. }
  35. else if(-a[]+-a[]>=tmp2-tmp1||a[]+a[]>=tmp2-tmp1||-a[]+a[]>=tmp2-tmp1)
  36. {
  37. printf("2\n");
  38. }
  39. else
  40. {
  41. printf("3\n");
  42. }
  43.  
  44. }
  45. else
  46. {
  47. if(-a[]>=tmp1-tmp2||a[]>=tmp1-tmp2)
  48. {
  49. printf("1\n");
  50. }
  51. else if(-a[]+-a[]>=tmp1-tmp2||a[]+a[]>=tmp1-tmp2||-a[]+a[]>=tmp1-tmp2)
  52. {
  53. printf("2\n");
  54. }
  55. else
  56. {
  57. printf("3\n");
  58. }
  59. }
  60. return ;
  61. }
C. Two TVs
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp is a great fan of television.

He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.

Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.

Polycarp wants to check out all n shows. Are two TVs enough to do so?

Input

The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows.

Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.

Output

If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).

Examples
input
  1. 3
    1 2
    2 3
    4 5
output
  1. YES
input
  1. 4
    1 2
    2 3
    2 3
    1 2
output
  1. NO

题意;给出喜欢看的节目的开始和结束时间,有两台电视,问能否所有节目是否都能接收到。

题解;把开始时间和结束时间分别sort()一下,只要第i个节目的结束时间比第i+2节目开始时间早,就行。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define ll long long
  6. using namespace std;
  7. const int maxn=2e5+;
  8. const ll inf=0x4f4f4f4f4f;
  9. int n,k;
  10. /*struct node
  11. {
  12. int l,r;
  13. bool operator<(const node b)const
  14. {
  15. return l==b.l?r<b.r:l<b.l;
  16. }
  17. }a[maxn];*/
  18. int l[maxn],r[maxn];
  19. int main()
  20. {
  21. scanf("%d",&n);
  22. for(int i=;i<n;i++)
  23. {
  24. scanf("%d %d",&l[i],&r[i]);
  25. }
  26. sort(l,l+n);
  27. sort(r,r+n);
  28. for(int i=;i<n-;i++)
  29. {
  30. if(l[i+]<=r[i])
  31. {
  32. printf("NO\n");return ;
  33. }
  34. }
  35. printf("YES\n");
  36. return ;
  37. }
D. Driving Test
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.

  • speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type);
  • overtake is allowed: this sign means that after some car meets it, it can overtake any other car;
  • no speed limit: this sign cancels speed limit if any (car can move with arbitrary speed after this sign);
  • no overtake allowed: some car can't overtake any other car after this sign.

Polycarp goes past the signs consequentially, each new sign cancels the action of all the previous signs of it's kind (speed limit/overtake). It is possible that two or more "no overtake allowed" signs go one after another with zero "overtake is allowed" signs between them. It works with "no speed limit" and "overtake is allowed" signs as well.

In the beginning of the ride overtake is allowed and there is no speed limit.

You are given the sequence of events in chronological order — events which happened to Polycarp during the ride. There are events of following types:

  1. Polycarp changes the speed of his car to specified (this event comes with a positive integer number);
  2. Polycarp's car overtakes the other car;
  3. Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer);
  4. Polycarp's car goes past the "overtake is allowed" sign;
  5. Polycarp's car goes past the "no speed limit";
  6. Polycarp's car goes past the "no overtake allowed";

It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).

After the exam Polycarp can justify his rule violations by telling the driving instructor that he just didn't notice some of the signs. What is the minimal number of signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view?

Input

The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events.

Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event.

An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car, if it is the query of third type, then it's new speed limit).

It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).

Output

Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.

Examples
input
  1. 11
    1 100
    3 70
    4
    2
    3 120
    5
    3 120
    6
    1 150
    4
    3 300
output
  1. 2
input
  1. 5
    1 100
    3 200
    2
    4
    5
output
  1. 0
input
  1. 7
    1 20
    2
    6
    4
    6
    6
    2
output
  1. 2
Note

In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120.

In the second example Polycarp didn't make any rule violation.

In the third example Polycarp should say he didn't notice both "no overtake allowed" that came after "overtake is allowed" sign.

题意:就是驾驶考试,他会看到四个不同的标志,有不同要求,然后给出他在考试过程中的行为,问他至少要告诉教练有多少个标志没看到,才是算没有犯错(这题重要的是看懂题意)

题解:模拟吧,把限速要求记下就行

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<vector>
  6. #define ll long long
  7. using namespace std;
  8. const int maxn=2e5+;
  9. const ll inf=0x4f4f4f4f4f;
  10. int n,k;
  11. vector<int>lim;
  12. int l[maxn],r[maxn];
  13. int main()
  14. {
  15. scanf("%d",&n);
  16. int ans=;
  17. int s=,num=;
  18. bool cc=false;
  19. while(n--)
  20. {
  21. int op,t;
  22. scanf("%d",&op);
  23. if(op==)
  24. {
  25. scanf("%d",&s);
  26. while(lim.size()&&s>lim.back())
  27. {
  28. lim.pop_back();ans++;
  29. }
  30. }
  31. else if(op==)
  32. {
  33. int l;
  34. scanf("%d",&l);
  35. lim.push_back(l);
  36. while(lim.size()&&s>lim.back())
  37. {
  38. lim.pop_back();ans++;
  39. }
  40. }
  41. else if(op==)
  42. {
  43. if(!cc)
  44. {
  45. ans+=num;num=;
  46. }
  47. }
  48. else if(op==)
  49. {
  50. cc=true;num=;
  51. }
  52. else if(op==)
  53. {
  54. lim.clear();
  55. }
  56. else
  57. {
  58. cc=false;num++;
  59. }
  60. }
  61. printf("%d\n",ans);
  62. return ;
  63. }

http://codeforces.com/contest/845的更多相关文章

  1. codeforces 725D . Contest Balloons(贪心+优先队列)

    题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...

  2. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  3. http://codeforces.com/contest/349

    A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. CodeForces - 725D Contest Balloons 贪心

              D. Contest Balloons          time limit per test 3 seconds         memory limit per test 2 ...

  5. http://codeforces.com/contest/555/problem/B

    比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...

  6. http://codeforces.com/contest/610/problem/D

    D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. http://codeforces.com/contest/612/problem/D

    D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  8. http://codeforces.com/contest/536/problem/B

    B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. http://codeforces.com/contest/535/problem/C

    C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. XMind入门教程

    最近在总结一些框架知识的时候,总找不到一款好的软件来画流程图,后来在网上查找这方面的东西,找到了 XMind,发现用来画思维导图还挺好的,看起来思路清晰,美观.那么便将使用的一些经验分享给大家. 1. ...

  2. Python教程百度网盘哪里有?

    Python为我们提供了非常完善的基础代码库,覆盖了网络.文件.GUI.数据库.文本等大量内容,被形象地称作"内置电池(batteries included)".带你快速入门的Py ...

  3. 推荐一款接口文档在线管理系统-MinDoc

    项目简介 MinDoc 是一款针对IT团队开发的简单好用的文档管理系统. MinDoc 的前身是 SmartWiki 文档系统.SmartWiki 是基于 PHP 框架 laravel 开发的一款文档 ...

  4. HTML+CSS画一朵向日葵

    前几天看到一张图片,倔强的向日葵.(BGM,<倔强>) 看着挺有感触,就想用CSS做一个向日葵. 最终效果图如下: 主要的难点就在花瓣的处理上,css暂时没有做到这样的尖角圆弧. 我想到的 ...

  5. 使用js jquery分别获取地址栏参数值

    使用JS获取地址栏参数 方法一: function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +& ...

  6. Linux-grep 命令和find 命令 (6)

    grep与find区别: grep:查找指定目录下过滤文本文件中行数据 find:查找指定目录下文件 grep使用 格式:   grep "text"   *  [选项] 选项: ...

  7. Markdown(editormd)语法解析成html

    我们在一些网站中可以见到一款网页编辑器--markdown: 这是一款功能强大的富文本编辑器,之前自己在网页上使用的时候遇到了一点点的问题,现在跟大家分享下 在我们写了文章之后是需要将内容保存到数据库 ...

  8. jQ的一些常识

    $(window).width()//可视区宽度 $(document).width()//整个页面文档流的宽度 $('body').width()//body元素的宽度(注意jQ获取body对象有引 ...

  9. 测试驱动开发(TDD)

    测试驱动开发的基本概念 为什么会出现测试驱动开发 当有一个新的任务时,往往第一个念头就是如何去实现它呢? 拿到任务就开始编码,一边写,变修改和设计 我已经调试了好几遍,应该不会有问题了,好了,先休息一 ...

  10. 团队作业4——第一次项目冲刺 tHe LaSt dAy

    项目冲刺--终点 敏捷冲刺最后一天,没想到前一天就上榜了,我也很无奈啊. 那今天就老老实实写一篇博客好了. Mission 这次敏捷冲刺呢,我们主要做了前端页面,后台的数据库和添加了基本的增删查改的功 ...