hdu 5143 NPY and arithmetic progression(暴力+思维)
NPY and arithmetic progression Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 864 Accepted Submission(s): 281
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, , 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?
Input The first line contains a integer T — the number of test cases (). 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 3
1 2 2 1
1 0 0 0
3 0 0 0
Sample Output Yes No Yes Hint In 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 3 4四种元素,问能不能构成长度大于3等差数列(可能不止一个)且没有剩余
思路:不难发现只有四种情况
1 2 3
2 3 4
1 2 3 4
111 222 333 444
对于1 2 3 4任何一个数,例如1
它被用到只有1 2 3 /1 2 3 4/1 1 1这三种情况
对于前两者的任何一个,如果数量大于等于3,就可以构成111的等差数列,所以只需考虑前两者数量为0 1 2的情况
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 200005
const double eps = 1e-8;
using namespace std;
inline ll read()
{
char ch = getchar(); ll s = 0, w = 1;
while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
return s * w;
}
inline void write(ll x)
{
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
putchar(x % 10 + 48);
}
ll t=read();
inline bool judge(ll a,ll b,ll c,ll d)
{
// 1 2 3 2 3 4 1 2 3 4
for(rg i=0;i<3;i++)
{
for(rg j=0;j<3;j++)
{
for(rg k=0;k<3;k++)
{
if(((!(a-i-k))||(a-i-k)>=3)&&((!(b-i-j-k))||(b-i-k-j)>=3)&&((!(c-i-j-k))||(c-i-k-j)>=3)&&((!(d-j-k))||(d-k-j)>=3))
{
return 1;
}
}
}
}
return 0;
}
int main()
{
while(t--)
{
ll a=read(),b=read(),c=read(),d=read();
judge(a,b,c,d)?cout<<"Yes"<<endl:cout<<"No"<<endl;
}
return 0;
}
- Asp.net页面生命周期
- Premiere&After Effects的实时预览插件开发
- 委托与事件
- 一款批量修改AE模板的工具
- 深入线程
- 【插件开发】—— 2 插件入门
- 线程间通讯:WaitHandler使用实例及分析
- 域名Deskbike.com刚注册没多久就以五位数结拍
- 一起Polyfill系列:Function.prototype.bind的四个阶段
- winform实现拼图游戏
- 一起Polyfill系列:让Date识别ISO 8601日期时间格式
- Oracle 监听器无法启动(TNS-12537,TNS-12560,TNS-00507)
- Javascript Prototypes之旅(A Plain English Guide to JavaScript Prototypes译文)
- Python补充03 Python内置函数清单
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- crontab JAVA_HOME not found
- Centos7 源码安装mysql5.6
- mysql登录时报socket找不到终极解决方案
- Grafana将数据库由sqlite3改为mysql
- Python自学成才之路 带有参数的装饰器
- Grafana 将默认的元数据库 sqlite 改为 mysql
- 使用IDEA整合spring4+spring mvc+hibernate
- springmvc中@PathVariable和@RequestParam的区别
- centos7 安装mysql5.6
- bashdb安装及调试shell脚本
- linux awk指令详解
- linux sed指令详解
- Grafana使用zabbix自定义模板
- linux shell之变量的使用规则
- 第11期:压缩表