觉得浮夸了四年,漠然发现原来是浮躁了四年!

hdu 2942(Pairs)

Pairs

Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 329 Accepted Submission(s): 159


Problem Description
Given n positive integers, is it possible to divide them into pairs so that the sum of each pair is the same?
 

 

Input
The input contains several test cases. The first line of each case contains a single integer n (2 ≤ n ≤ 100). The second line contains n positive integers not greater than 1000. These numbers are sorted in non-decreasing order. The last case is followed by a single zero, which should not be processed.
 

 

Output
For each case, output ‘Yes’ or ‘No’ depending on whether or not the pairing is possible.
 

 

Sample Input
4 1 3 4 6 3 1 1 1 0
 

 

Sample Output
Yes No
 

 

Source
 
Analysis:
The problem is very easy if you really understand it.So read the problem correct is very important!The problem descripe that if it possible devide the numbers into pairs  not two parts.
So  good English skills and careful reading the problem description for acmer is a must!
 
Code view:

#include<iostream>
using namespace std;
int num[1005];
int n;
int main()
{
 int i;
 while(scanf("%d",&n)&&n)
 {
  int flag=0;
  for(i=1;i<=n;i++)
   scanf("%d",&num[i]);
  if(n%2)
  {
     flag=1;
  }
  int sum=num[1]+num[n];
  for(i=2;i<=n/2;i++)
  {
       if(num[i]+num[n-i+1]!=sum)
    {
     flag=1;
     break;
    }
  }
  if(!flag)
   cout<<"Yes"<<endl;
  else
   cout<<"No"<<endl;
 }
 return 0;
}
  

 Haha,a piece of cake!

posted @ 2012-10-29 10:18  heat nan  阅读(212)  评论(0编辑  收藏  举报