HDU 5143 NPY and arithmetic progression(思维)
http://acm.hdu.edu.cn/showproblem.php?pid=5143
题意:
给定数字1,2,3,4.的个数每个数字能且仅能使用一次,组成多个或一个等差数列(长度大于等于3),问能否成功。
思路:
可以发现等差数列只有(123,234,1234和长度>=3的常数列),如果选择非常数数列(123,234,1234)数量大于等于3,
可以变为三个或4个常数列,例如(123,123,123)变为(111,222,333)。所以从0-2枚举选择非常数列的数量,再判断能否用常数列覆盖剩下的(如果数字长度正好为0或≤3就可以)。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = +; int a1,a2,a3,a4; bool check(int a, int b, int c, int d)
{
if((a>=||a==)&&(b>=||b==)&&(c>=||c==)&&(d>=||d==)) return true;
return false;
} int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&a1,&a2,&a3,&a4);
bool flag = false;
if(check(a1,a2,a3,a4)) flag=true;
else
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(int k=;k<=;k++)
{
if(check(a1-i-k,a2-i-j-k,a3-i-j-k,a4-j-k)) flag=true;
}
}
}
if(flag) puts("Yes");
else puts("No");
}
return ;
}
HDU 5143 NPY and arithmetic progression(思维)的更多相关文章
- BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...
- CF 1114 E. Arithmetic Progression
E. Arithmetic Progression 链接 题意: 交互题. 有一个等差序列,现已打乱顺序,最多询问60次来确定首项和公差.每次可以询问是否有严格大于x的数,和查看一个位置的数. 分析: ...
- HDU 5143 DFS
分别给出1,2,3,4 a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...
- POJ3495 Bitwise XOR of Arithmetic Progression
Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 772 Accepted: 175 Description Write ...
- HDU 5144 NPY and shot(物理运动学+三分查找)
NPY and shot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 5142 NPY and FFT
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5142 NPY and FFT Description A boy named NPY is learn ...
- hdu 5144 NPY and shot 物理+三分
NPY and shot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- HDU 5145 NPY and girls 莫队+逆元
NPY and girls Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more! ...
- hdu 3336 Count the string(思维可水过,KMP)
题目 以下不是KMP算法—— 以下是kiki告诉我的方法,好厉害的思维—— 就是巧用标记,先标记第一个出现的所有位置,然后一遍遍从标记的位置往下找. #include<stdio.h> # ...
随机推荐
- mysql安装使用
linux系统 mysql-5.7.14-linux.zip部署包支持在CentOS 6.x/7.x 服务器硬盘大小要求 a) /data/mysql_data 如果存在该独立分区,要求该分区 &g ...
- JDBC-day02
JDBC:数据库连接 java database connectivity ###properties 属性对象,用于读取*.properties属性配置文件中的数据 -为什么使用:之前写法是把数 ...
- GUI常用对象介绍2
%示意line对象的用法 hf=figure; hl=plot([:]); %示意line对象的属性 get(hl) %设置line的颜色 set(hl,'Color','r'); %设置每个点形状 ...
- 51Nod 1256 乘法逆元
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1256 给出2个数M和N(M < N),且M与N互质,找 ...
- NFS服务端与客户端配置
#首先确认系统中是否安装了对于的软件 rpm -qa|grep -i nfs #在有网络的情况下使用YUM安装NFS.rpcbind软件包 yum install lrzsz nmap tree do ...
- ubuntu_查看software
感谢原博主的分享 ubuntu安装和查看已安装 说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行 ...
- redis 的数据结构
Redis 数据类型 详解见: http://www.runoob.com/redis/redis-strings.html Redis支持五种数据类型:string(字符串),hash(哈希),li ...
- Censor SCU - 4438
frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...
- oracle 11g中的自动维护任务管理
因为人员紧缺,最近又忙着去搞性能优化的事情,有时候真的是不想再搞这个事情,只是没办法,我当前的绩效几乎取决于这个项目的最终成绩,所以不管是人的事还是事的事,都得去让他顺利推进. 前段时间发生还有几台服 ...
- intel webrtc 部署
org link conference server Configure the MCU server 1. set the maximum numbers of open files, runnin ...