Codeforces Round #445 A. ACM ICPC【暴力】
2 seconds
256 megabytes
standard input
standard output
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
1 3 2 1 2 1
YES
1 1 1 1 1 99
NO
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
【题意】:存在某三个和另外三个相等输出YES,否则输出NO
【分析】:暴力
【代码】:
#include <bits/stdc++.h> using namespace std;
const int maxn = ; int main()
{
int a[],sum[];
memset(sum,,sizeof(sum));
for(int i=;i<=;i++)
{
cin>>a[i];
if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} if(a[]+a[]+a[]==a[]+a[]+a[])
{
printf("YES\n");
return ;
} }
printf("NO\n");
return ;
}
我的傻逼代码
#include <bits/stdc++.h> using namespace std;
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int a[],sum=; int main()
{
for(int i=;i<;i++)
{
cin>>a[i];
sum+=a[i];
}
for(int i=;i<;i++)
{
for(int j=i+;j<;j++)
{
for(int k=j+;k<;k++)
{
if(*(a[i]+a[j]+a[k])==sum)
{
printf("YES\n");
return ;
}
}
}
}
printf("NO\n");
}
枚举
#include <bits/stdc++.h> using namespace std; int main() {
int a[];
for(int i = ; i < ; i++) cin >> a[i];
sort(a, a + );
do{
if((a[] + a[] + a[]) == (a[] + a[] + a[])){
cout << "YES";
return ;
}
}while(next_permutation(a, a + ));
cout << "NO";
return ;
}
next_permutation的妙用
最新文章
- LINQ系列:LINQ to SQL Select查询
- 关于实现手机端自动获取天气的demo
- <;转>;linux crontab 定时任务
- FineUI疑难杂症
- YUV422/YUV420播放
- testNG中@Factory详解
- android 使用两个surfaceview 在摄像机画面上绘图
- 提高MySQL数据库查询效率的几个技巧(转载)
- PHP自学4——通过函数将数组数据输出到html的Table标签中(使用函数的例子)
- c++中,size_typt, size_t, ptrdiff_t 简介
- stormzhang的推荐!
- Object lifetime
- 使用Ansible进行项目的自动部署(Tomcat、Weblogic)
- ES6常用语法(上)
- MySQL 权限相关
- 解决y7000笔记本ubuntu18.04下 休眠挂起后唤醒花屏
- mysql数据库修改数据表引擎的方法
- 【坑】https证书链不完整的坑
- HDU 1348 Wall 【凸包】
- 通过GeneXus如何快速构建微服务架构