codeforce 11 11 A B
来源:互联网 发布:csmhuan实时数据 编辑:程序博客网 时间:2024/05/17 18:25
A. Heads or Tails
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the end of the game. If boys have the same number of points, the game finishes with a draw.
At some point, Valera lost his count, and so he can not say exactly what the score is at the end of the game. But there are things he remembers for sure. He remembers that the entire game Vasya got heads at least a times, and Petya got heads at least b times. Moreover, he knows that the winner of the game was Vasya. Valera wants to use this information to know every possible outcome of the game, which do not contradict his memories.
The single line contains four integers x, y, a, b (1 ≤ a ≤ x ≤ 100, 1 ≤ b ≤ y ≤ 100). The numbers on the line are separated by a space.
In the first line print integer n — the number of possible outcomes of the game. Then on n lines print the outcomes. On the i-th line print a space-separated pair of integers ci, di — the number of heads Vasya and Petya got in the i-th outcome of the game, correspondingly. Print pairs of integers (ci, di) in the strictly increasing order.
Let us remind you that the pair of numbers (p1, q1) is less than the pair of numbers (p2, q2), if p1 < p2, or p1 = p2 and also q1 < q2.
3 2 1 1
3 2 1 3 1 3 2
2 4 2 2
0
简单题。。。
代码:
1 #include<iostream> 2 using namespace std; 3 int sum1[10010]; 4 int sum2[10010]; 5 int main(){ 6 int a,b,c,d; 7 while(cin>>a>>b>>c>>d){ 8 // memset(a) 9 int times=0;10 for(int i=1;i<=a;i++){11 for(int j=0;j<i;j++){12 if(i>=c&&j>=d&&j<=b){13 sum1[times]=i;14 sum2[times]=j;15 times++;16 // cout<<i<<" "<<j<<" "<<a<<" "<<i<<endl;17 }18 }19 }20 cout<<times<<endl;21 for(int k=0;k<times;k++){22 cout<<sum1[k]<<" "<<sum2[k]<<endl;23 }24 }25 return 0;26 }27
B:
A coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li, ri].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [a, b] covers segment [c, d], if they meet this condition a ≤ c ≤ d ≤ b.
The first line contains integer n (1 ≤ n ≤ 105) — the number of segments. Next n lines contain the descriptions of the segments. The i-th line contains two space-separated integers li, ri (1 ≤ li ≤ ri ≤ 109) — the borders of the i-th segment.
It is guaranteed that no two segments coincide.
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
3 1 1 2 2 3 3
-1
6 1 5 2 3 1 10 7 10 7 7 10 10
3
还是简单题;
对每段的头进行排序,再对尾进行排序。。。求最小的头和最大的尾。。。
代码:
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 struct node{ 5 int start; 6 int end; 7 }; 8 node a1[100005]; 9 int b[100005];10 int c[100005];11 int main(){12 int n;13 while(cin>>n){14 for(int i=0;i<n;i++){15 cin>>a1[i].start>>a1[i].end;16 b[i]=a1[i].start;17 c[i]=a1[i].end;18 }19 sort(b,b+n);20 sort(c,c+n);21 int resstart=b[0];22 int resend=c[n-1];23 int k;24 for(k=0;k<n;k++){25 if(a1[k].start<=resstart&&a1[k].end>=resend){26 cout<<k+1<<endl;27 break;28 }29 }30 if(k>=n)31 cout<<"-1"<<endl;32 }33 return 0;34 }
1 #include<iostream> 2 using namespace std; 3 int sum1[10010]; 4 int sum2[10010]; 5 int main(){ 6 int a,b,c,d; 7 while(cin>>a>>b>>c>>d){ 8 // memset(a) 9 int times=0;10 for(int i=1;i<=a;i++){11 for(int j=0;j<i;j++){12 if(i>=c&&j>=d&&j<=b){13 sum1[times]=i;14 sum2[times]=j;15 times++;16 // cout<<i<<" "<<j<<" "<<a<<" "<<i<<endl;17 }18 }19 }20 cout<<times<<endl;21 for(int k=0;k<times;k++){22 cout<<sum1[k]<<" "<<sum2[k]<<endl;23 }24 }25 return 0;26 }27
- codeforce 11 11 A B
- codeforce 11 04 A
- codeforce 11 A
- codeforce 11B 思维题
- codeforce 11B. Jumping Jack
- codeforce 11 27 A C
- codeforce 237A 237B
- CodeForce 339:A+B+C
- Codeforce 445(A,B,C,D,E)
- Codeforce 621(A,B,C,D,E)
- Codeforce#385B.Hongcow Solves A Puzzle
- codeforce 698B Fix a Tree
- 6.29 CodeForce 818 A/B解题报告
- CodeForce 825B Five-In-a-Row
- CodeForce 837 A/B/C解题报告
- CodeForce #429 DIV2 A B C题解
- Codeforce Round #439 A B C 题解
- Codeforce A
- codeforce 11 04 A
- 最大流模板 Ford-Fulkerson and Dinic
- usaco 1.1 Broken Necklace
- usaco 1.1 Miking Cows
- usaco 1.1 Trasformations
- codeforce 11 11 A B
- poj 1251
- 次小生成树 (poj 1679)
- usaco 29 name that number
- usaco 1.2 Palindromic Squares
- Training@USC Greedy Tino
- usaco 1.2 76 mixing milk 90 Dual Palindromes
- lua table to string,string to table
- usaco 24 barn repair