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 regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
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
1 3 2 4
YES
1
3 3
NO
必须保证每局都可以赢
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int a[205],n; int main() { cin>>n; for(int i=0;i<2*n;i++) cin>>a[i]; sort(a,a+2*n); puts(a[n]>a[n-1]?"YES":"NO"); return 0; }
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.
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.
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
000000
0
123456
2
111000
1
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.
暴力循环就行
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) int n,a[9],b[9],k; int pow(int x,int y) { int ans=1; while(y) { if(y&1) ans*=x; y>>=1; x*=x; } return ans; } void solve(int x,int y) { if(x==7) { if(b[1]+b[2]+b[3]==b[4]+b[5]+b[6]) k=min(k,y); return ; } for(int i=0;i<=9;i++) { b[x]=i; if(b[x]==a[x]) solve(x+1,y); else solve(x+1,y+1); } } int main() { while(scanf("%d",&n)!=EOF) { for(int i=1;i<=6;i++) a[i]=n/pow(10,6-i)%10; k=10; solve(1,0); printf("%d ",k); } return 0; }
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?
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.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
3
1 2
2 3
4 5
YES
4
1 2
2 3
2 3
1 2
NO
我猜测每次看的电视节目必须时完整的,刚开始我以为时线段树,只要一个电视可以看一部分就行了,WA了。
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) pair<int,int>p[200006]; int n,ans,pos; int main() { while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second); sort(p,p+n); ans=pos=-1; for(int i=0;i<n;i++) { if(ans<p[i].first) ans=p[i].second; else if(pos<p[i].first) pos=p[i].second; else {puts("NO");goto k;} } puts("YES"); k:; } return 0; }
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:
- Polycarp changes the speed of his car to specified (this event comes with a positive integer number);
- Polycarp's car overtakes the other car;
- Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer);
- Polycarp's car goes past the "overtake is allowed" sign;
- Polycarp's car goes past the "no speed limit";
- 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?
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).
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.
11
1 100
3 70
4
2
3 120
5
3 120
6
1 150
4
3 300
2
5
1 100
3 200
2
4
5
0
7
1 20
2
6
4
6
6
2
2
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.
题目是很长,但按照要求来很简单。
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) int n,ans,t,x,currentspeed,limitspeed; int main() { while(scanf("%d",&n)!=EOF) { stack<int>q; q.push(400); t=0,ans=0; while(n--) { scanf("%d",&x); if(x==1) scanf("%d",¤tspeed); else if(x==2) ans+=t,t=0; else if(x==3) scanf("%d",&limitspeed),q.push(limitspeed); else if(x==4) t=0; else if(x==5) q.push(400); else if(x==6) t++; while(currentspeed>q.top()) ans++,q.pop(); } printf("%d ",ans); } return 0; }