A. Chess Tourney
 

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个数  让你选择n个数  然后 必须使得 选的n个数  比没选的n个数里面的数都要大

就很基本 sort一下  比较一下1-n 中最大的  和 n+1 到2*n中最小的 是否相等

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int s[];
int main ()
{
int n;
cin>>n;
for(int i=;i<=*n;i++)
cin>>s[i];
sort(s+,s+*n+);
if(s[n]==s[n+])
puts("NO");
else
puts("YES");
}
B. Luba And The Ticket
 

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.

 
题意 给你6个数字 问你使得 前三个和 和后面三个和 相等的 数字改动的最少数量
 
大概我是分情况讨论的   下面就是我AC的代码  把 0 ,1 ,2 的情况都讨论了   结果 当然是GG的了,并且写的时候脑子时刻会短路 不知道会x - 0 还是9 - x
大概是我数学逻辑不好的吧
 
#include<bits/stdc++.h>
using namespace std; char a[],b[]; int main ()
{
for(int i=;i<;i++)
cin>>a[i];
for(int i=;i<;i++)
cin>>b[i];
sort(a,a+);sort(b,b+); int s1=,s2=;
for(int i=;i<;i++)
s1+=a[i],s2+=b[i];
if(s1 == s2)//0的情况
{
puts("");
return ;
}
if(s1 > s2)//1的情况
{
int mx = max(''-b[],a[]-'');
//cout << '9'-b[0]<<endl;
//cout<<a[0]-'0'<<endl;
if(s1 - s2 <= mx)
{
puts("");
return ;
}
}
if(s2 > s1)
{
int mx = max(''-a[],b[]-'');
if(s2 - s1 <= mx)
{
puts("");
return ;
}
}
if(s1 < s2)
{
int mx = max(''-a[] + b[]-'',max(''-a[]+''-a[],b[]-''+b[]-'')); if(s2-s1 <= mx)
{
puts("");
return ;
}
}
if(s2 < s1)
{
int mx = max(''-b[] + a[]-'',max(''-b[]+''-b[],a[]+a[]-''-''));
if(s1-s2 <= mx)
{
puts("");
return ;
}
}
puts("");
}
下面是看到别人的blog后 写出来的  感觉自己是真的菜
//都是知识盲区 抓紧补
#include<bits/stdc++.h>
using namespace std;
char s[];
int num[]; bool cmp(int a,int b)
{
return a>b;
}
int main ()
{
int s1 =,s2 = ;
cin>>s;
for(int i=;i<;i++)
s1+= s[i] -'';
for(int i=;i<;i++)
s2+= s[i] -'';
if(s1 == s2)
{
puts("");
return ;
}
if(s1 > s2) //前面数字大 大的要尽量变0 小的尽量变9
{
for(int i=;i<;i++)
num[i] = s[i]-'' - ;
for(int i=;i<;i++)
num[i] = - (s[i]-'');
sort(num,num+,cmp);
for(int i=;i<;i++)
num[i] += num[i-];
for(int i=;i<;i++)
{
if(num[i] >= s1-s2)
{
cout << i+<<endl;
return ;
}
}
}
if(s2 > s1)
{
for(int i=;i<;i++)
num[i] = -(s[i]-'');
for(int i=;i<;i++)
num[i] = (s[i]-'')-;
sort(num,num+,cmp);
for(int i=;i<;i++)
num[i] += num[i-]; for(int i=;i<;i++)
{
if(num[i] >= s2-s1)
{
cout << i+<<endl;
return ;
}
}
}
}
 
C. Two TVs
 

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).

题意:题目大概能看懂的吧    一个小trick 就是 一个结束和一个开始的时间重合的话,是不可以使用相同的电视的

//感觉像是模拟
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int n;
struct node
{
int l,r;
bool operator<(const node& a)const
{
return l < a.l;
}
}s[maxn];
priority_queue<int,vector<int>,greater<int> >s1,s2; int main ()
{
cin>>n;
for(int i=;i<=n;i++)
cin>>s[i].l >> s[i].r;
sort(s+,s+n+); for(int i=;i<=n;i++)
{
if(s1.empty())
{
s1.push(s[i].r);
continue;
}
if(s2.empty())
{
s2.push(s[i].r);
continue;
}
int now1 = s1.top();
if(now1 < s[i].l)
{
s1.pop();
s1.push(s[i].r);
continue;
}
int now2 = s2.top();
if(now2 < s[i].l)
{
s2.pop();
s2.push(s[i].r);
continue;
}
puts("NO");return ;
}
puts("YES");
}

Educational Codeforces Round 27 A B C的更多相关文章

  1. Educational Codeforces Round 27 补题

    题目链接:http://codeforces.com/contest/845 A. Chess Tourney 水题,排序之后判断第n个元素和n+1个元素是不是想等就可以了. #include < ...

  2. Educational Codeforces Round 27

    期末后恢复性训练,结果完美爆炸... A,题意:2n个人,分成两队,要求无论怎么分配,第一队打赢第二队 #include<bits/stdc++.h> #define fi first # ...

  3. Educational Codeforces Round 27 F. Guards In The Storehouse

    F. Guards In The Storehouse time limit per test 1.5 seconds memory limit per test 512 megabytes inpu ...

  4. Educational Codeforces Round 27 D. Driving Test

    单调栈 题意看了半天... #include <cstdio> #include <cstdlib> #include <cmath> #include <c ...

  5. Educational Codeforces Round 117 (Rated for Div. 2)

    Educational Codeforces Round 117 (Rated for Div. 2) A. Distance https://codeforces.com/contest/1612/ ...

  6. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  7. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  8. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  9. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

随机推荐

  1. Django单元测试简单示例

    对一个功能的验证往往是需要很多多测试用例,可以把测试用例集合在一起执行,这就产生了测试套件TestSuite 的概念,它是用来组装单个测试用例,规定用例的执行的顺序,而且TestSuite也可以嵌套T ...

  2. 深入浅出 TCP/IP 协议栈

    写的不错:http://www.cnblogs.com/onepixel/p/7092302.html#3899256

  3. SQL SERVER 事务执行情况跟踪分析

    [sql] view plain copy ---查看现在所有的事务 select '正在运行事务的会话的 ID'=session_id, --session_id与transaction_id的对应 ...

  4. Kettle定时抽取两个库中的两个表到目标库SYS_OPLOG表

     A库a表(红色为抽取字段): 关联用户表: B库b表(红色为抽取字段): 关联用户表  C目标库SYS_OPLOG表(c表) 利用kettle抽取A库a表(具体名称见上图),B库b表的上面红色框起来 ...

  5. oj1500(Message Flood)字典树

    大意:输入几个字符串,然后再输入几个字符串,看第一次输入的字符串有多少没有在后面的字符串中出现(后输入的字符串不一定出现在之前的字符串中) #include <stdio.h> #incl ...

  6. soapUI-property Transfer

    1.1.1  Property Transfer 创建或双击现有的Property-Transfer TestStep将打开以下窗口: 左侧的列表显示了此TestStep中配置的传输,添加和管理所需的 ...

  7. Vue.Js加入bootstrap及jquery,或加入其他插件vue-resource,vuex等

    .引入jquery 项目目录下输入 cnpm install jquery --save-dev      用npm下载jq依赖 若想加入其他js库,如vue-resource,执行命令cnpm in ...

  8. Perl中的正则表达式(五)

    正则表达式(Regular Expression),在Perl里边通常也叫做模式(Pattern),用来表示匹配(或不匹配)某个字符串的特征模板. 使用简单模式:若模式匹配的对象是$_的内容,只要把模 ...

  9. VS2010/MFC编程入门之三十七(工具栏:工具栏的创建、停靠与使用)

    鸡啄米在上一节教程中讲了工具栏资源及CToolBar类,本节继续讲解工具栏的相关知识,主要内容包括工具栏的创建.停靠与使用. 工具栏的使用 上一节中鸡啄米提到过,一般情况下工具栏中的按钮在菜单栏中都有 ...

  10. 搭建Linux-java web运行环境之一:安装jdk+tomcat

    环境 OS:Red Hat Enterprise Linux Server release 7.3 (Maipo) JDK:jdk-7u80-linux-x64.tar.gz Tomcat:apach ...