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

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 @   heat nan  阅读(216)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示