COCI 2009/2010 ——B

COCI 2009/2010 Task MALI
1. round, 24. october 2009.
Author: Marko Ivankovi., Filip Barl
Mirko and Slavko are playing a new game. Again. Slavko starts each round by
giving Mirko two numbers A and B, both smaller than 100. Mirko then has to
slove the following task for Slavko: how to pair all given A numbers with all
given B numbes so that the maximal sum of such pairs is as small as
possible.
In other words, if during previous rounds Slavko gave numbers a1, a2, a3 .... an
and b1, b2, b3 ... bn, determine n pairings (ai, bj) such that each number in A
sequence is used in exactley one pairing, and each number in B sequenct is
used in exactely one pairing and the maximum of all sums ai + bj is minimal.
INPUT
The first line of input contains a single integer N (1 . N . 100000), number of
rounds.
Next N lines contain two integers A and B (1 . A, B . 100), numbers given by
Slavko in that round.
OUTPUT
Output consists of N lines, one for each round. Each line should contain the
smallest maximal sum for that round.
SCORING
Test cases worth 50% of total points have N . 200.
SAMPLE TESTS
input
3
2 8
3 1
1 4
output
10
10
9
input
3
1 1
2 2
3 3
output
2

3

4

题意:每一次a[]从小到大排,b[ ]从大到小排,这种时候一一对应为一种情况而此种情况的最大者即为此次所求,也可以说(a[]中的最小者加上b[]中的最大者之和与a[]中的最大者加上b[]中的最小者之和比较后的最大者即为此次所求)

代码大致:

 #include <stdio.h>
 
 int main( )
 {
 
   int n;
    int x,y;
   
   while(scanf("%d",&n)!=EOF)
   {
     int j,k;
  
      int   A[110000]={0},B[110000]={0};
     for( int i=1;i<=n;i++)
     {
       scanf("%d%d",&x,&y);
       ++A[x],++B[y];
       int a[110000]={0},b[110000]={0};
       int c1=0,c2=0;
       for( int k=1;k<100;k++)//记下此A[ ]的排序 , 注意有相同的故不能只k++下同
       {
       if(A[x])
       }
       for( int j=100;j>=1;j--)//记下统计此B[ ]的排序 
       {
       if(B[x])
    }
      
        int max=-1;
       for( k=1;k<=i;k++)//求最值
       {
       printf("a[k] = %d b[k] = %d\n",a[k],b[k]);
     
   int c=a[k]+b[k];
       if(max<c) max=c;
       }
       printf("%d\n",max);
     }
    
    
   }
   return 0;
 }

你可能感兴趣的:(oc)