hdu 5143 暴力枚举
来源:互联网 发布:网络丢包测试工具 编辑:程序博客网 时间:2024/06/06 02:10
NPY and arithmetic progression
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1100 Accepted Submission(s): 353
Problem Description
NPY is learning arithmetic progression in his math class. In mathematics, an arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant.(from wikipedia)
He thinks it's easy to understand,and he found a challenging problem from his talented math teacher:
You're given four integers,a1,a2,a3,a4 , which are the numbers of 1,2,3,4 you have.Can you divide these numbers into some Arithmetic Progressions,whose lengths are equal to or greater than 3?(i.e.The number of AP can be one)
Attention: You must use every number exactly once.
Can you solve this problem?
He thinks it's easy to understand,and he found a challenging problem from his talented math teacher:
You're given four integers,
Attention: You must use every number exactly once.
Can you solve this problem?
Input
The first line contains a integer T — the number of test cases (1≤T≤100000 ).
The next T lines,each contains 4 integersa1,a2,a3,a4(0≤a1,a2,a3,a4≤109) .
The next T lines,each contains 4 integers
Output
For each test case,print "Yes"(without quotes) if the numbers can be divided properly,otherwise print "No"(without quotes).
Sample Input
31 2 2 11 0 0 03 0 0 0
Sample Output
YesNoYesHintIn the first case,the numbers can be divided into {1,2,3} and {2,3,4}.In the second case,the numbers can't be divided properly.In the third case,the numbers can be divided into {1,1,1}.
题意理解不清楚:
第一:输入数组 1 2 2 1表示1个1 , 2个2 , 2个3 , 1个4
第二:常数组可以很长很长,非常数列只能是三个或者四个元素
非常数列有三种情况123 234 1234,枚举这三种情况后再用常数列进行覆盖即可
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int deal(int arr[]){ int flag=0; for(int i=1;i<=4;i++) if(arr[i]==0||arr[i]>=3) flag++; if(flag==4) return 1; else return 0;}int main(){ int T; int a[10],b[10]; //freopen("in.txt","r",stdin); scanf("%d",&T); while(T--) { for(int i=1;i<=4;i++){ scanf("%d",&a[i]); b[i]=a[i]; } int flag=0; for(int i=0;i<=2;i++){ for(int j=0;j<=2;j++){ for(int k=0;k<=2;k++){ a[1]-=(i+k); a[2]-=(i+j+k); a[3]-=(i+j+k); a[4]-=(j+k); if(deal(a)){ flag=1; goto temp; } for(int p=1;p<=4;p++) a[p]=b[p]; } } } temp:; if(flag) puts("Yes"); else puts("No"); } return 0;}
0 0
- hdu 5143 暴力枚举
- hdu 5143 暴力枚举,转换的思想
- hdu 3332 暴力枚举
- HDU 3823 暴力枚举
- hdu 3720 暴力枚举
- hdu 5024 暴力枚举
- hdu 4445 暴力枚举
- HDU 4007 暴力枚举
- hdu 5128 暴力枚举
- hdu 5228 暴力枚举
- hdu 5339 暴力枚举
- HDU 5610 暴力枚举
- hdu 5660 暴力枚举
- HDU-1015/暴力枚举
- HDU 1172 暴力枚举
- HDU-5578-暴力枚举
- hdu-4445 暴力枚举
- hdu 6058 暴力枚举
- 前端页面a标签嵌套a标签效果的两种解决方案
- 关键字
- node安装
- MySQL实现类似Oracle中start with功能
- “ORA-08176: 一致的读错误;回退数据不可用”
- hdu 5143 暴力枚举
- linux 终端下命令提示乱码
- 在Fragment继承类中更新UI。
- html实时监听input变化
- union all
- Jedis分片连接池(分布式)
- 关于-webkit-的一些用法
- Android Studio使用技巧---良心推荐的实用功能 Android Studio打包全攻略---从入门到精通
- 使用CABasicAnimation的基本使用