HDU 5776 sum(抽屉原理)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=5776
For each test case, there are two lines:
1.The first line contains two positive integers n, m (1≤n≤100000, 1≤m≤5000).
2.The second line contains n positive integers x (1≤x≤100) according to the sequence.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<cmath>
using namespace std;
#define N 100005 struct node
{
int num,r;
}k[N]; bool cmp(node a,node b)
{
if(a.r==b.r)
return a.num<b.num;
return a.r<b.r;
} int main()
{
long long sum,a;
int n,m;
bool flag;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
flag=false;
if(n>m)
flag=true;
sum=;
k[].num=;
for(int i=;i<=n;i++)
{
scanf("%lld",&a);
sum+=a;
k[i].r=sum%m;
k[i].num=i;
if(k[i].r==&&flag==false)
{
flag=true;
}
}
if(!flag)
{
sort(k+,k++n,cmp);
for(int i=;i<=n;i++)
{
if(k[i].r==k[i-].r)
{
flag=true;
break;
}
}
}
if(!flag)
printf("NO\n");
else
printf("YES\n");
}
return ;
}
HDU 5776 sum(抽屉原理)的更多相关文章
- Codeforces Round #319 (Div. 2) B. Modulo Sum 抽屉原理+01背包
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- HDU 5776 sum (模拟)
sum 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5776 Description Given a sequence, you're asked ...
- HDU 5776 sum (思维题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...
- HDU 5776 sum (前缀和)
题意:给定 n 个数,和 m,问你是不是存在连续的数和是m的倍数. 析:考虑前缀和,如果有两个前缀和取模m相等,那么就是相等的,一定要注意,如果取模为0,就是真的,不要忘记了,我当时就没记得.... ...
- HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题
分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...
- HDU 5776 sum
猜了一下,发现对了.n>m是一定有解的.所以最多m*m暴力,一定能找到.而T较小,所以能过. #pragma comment(linker, "/STACK:1024000000,10 ...
- HDU 4704 Sum (隔板原理 + 费马小定理)
Sum Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/131072K (Java/Other) Total Submiss ...
- hdu 5776 sum 前缀和
sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- HDU 5776 sum( 鸽巢定理简单题 )
链接:传送门 题意:给一个长为 n 的串,问是否有子串的和是 m 的倍数. 思路:典型鸽巢定理的应用,但是这里 n,m 的大小关系是不确定的,如果 n >= m 根据定理可以很简单的判定是一定有 ...
随机推荐
- 【Oracle】【2】复制表结构及其数据
--复制表结构及其数据 create table table_name_new as select * from table_name_old; --只复制表结构 ; --create table t ...
- h5网页跳转到app,若未安装app,则跳转app下载页面
if(isAndroid){ android(); function android(){ var ifr = document.createElement("iframe"); ...
- PostgreSQL&PostGIS完全安装
检查PostGIS.PostgreSQL.GEOS.GDAL.PROJ等各软件的版本依赖关系 http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQ ...
- Xshell中文乱码怎么处理?
改成如下图:
- 2015-09-29 js2
Javasript 六. 条件语句 1. 比较运算符 == .!=.>.>=.<.<= 转大/小写:toUpperCase().toLowerCase() 2. 逻辑运算符(与 ...
- ActiveMQ Advisory Message
http://activemq.apache.org/advisory-message.html ActiveMQ broker 内部维持了一些 topic,保存了一些系统信息,客户端可以订阅这些 t ...
- vue-router 路由钩子(hook)
钩子(hook)—劫持机制 路由钩子(守卫钩子): 1.全局钩子2.某个路由独享的钩子3.组件内钩子 三种路由钩子中都涉及到了三个参数,官方(https://router.vuejs.org/zh-c ...
- 如何利用redis key过期事件实现过期提醒
https://blog.csdn.net/zhu_tianwei/article/details/80169900 redis自2.8.0之后版本提供Keyspace Notifications功能 ...
- Mockito:一个强大的用于Java开发的模拟测试框架
https://blog.csdn.net/zhoudaxia/article/details/33056093 介绍 本文将介绍模拟测试框架Mockito的一些基础概念, 介绍该框架的优点,讲解应用 ...
- spoj220
题解: 后缀数组 把所有串连接起来 二分答案 代码: #include<cstdio> #include<cstring> #include<algorithm> ...