codeforce 11 11 A B

来源:互联网 发布:csmhuan实时数据 编辑:程序博客网 时间:2024/05/17 18:25

 

A. Heads or Tails
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Sample test(s)
Input
3 2 1 1
Output
3 2 1 3 1 3 2
Input
2 4 2 2
Output
0



简单题。。。

代码:

View Code
 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:

B. Big Segment
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Sample test(s)
Input
3 1 1 2 2 3 3
Output
-1
Input
6 1 5 2 3 1 10 7 10 7 7 10 10
Output
3



还是简单题;

对每段的头进行排序,再对尾进行排序。。。求最小的头和最大的尾。。。


代码:

View Code
 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