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!

转载于:https://www.cnblogs.com/heat-man/articles/2744081.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值