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!
分类:
Basic problem
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?