题目链接:

B. Modulo Sum

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a sequence of numbers a1, a2, ..., an, and a number m.

Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.

Input

The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.

Examples
input
3 5
1 2 3
output
YES
input
1 6
5
output
NO
input
4 6
3 1 1 3
output
YES
input
6 6
5 5 5 5 5 5
output
YES

题意:

能否找到一个子序列的和能被m整除;

思路:

有一道hdu的水题就是这样的,以前傻傻的居然不会做;就是把余数拿出来搞搞就好了;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=1e3+110;
const double eps=1e-12; int n,m,a[N],vis[maxn],temp[maxn];
int main()
{
read(n);read(m);
int flag=0;
For(i,1,n)read(a[i]);
vis[0]=1;
For(i,1,n)
{
a[i]%=m;
int t=(m-a[i])%m;
if(vis[t]){flag=1;break;}
mst(temp,0);
for(int j=0;j<m;j++)
{
if(vis[j])temp[(j+a[i])%m]=1;
}
for(int j=0;j<m;j++)
if(temp[j])vis[j]=1;
}
if(flag)cout<<"YES\n";
else cout<<"NO\n";
return 0;
}

  

codeforces 577B B. Modulo Sum(水题)的更多相关文章

  1. 【CodeForces 577B】Modulo Sum

    题 题意 给你n(1 ≤ n ≤ 106)个数a1..an(0 ≤ ai ≤ 109),再给你m( 2 ≤ m ≤ 103)如果n个数的子集的和可以被m整除,则输出YES,否则NO. 分析 分两种情况 ...

  2. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  3. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

  4. SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)

    #include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...

  5. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  6. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  7. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

  8. codeforces 659A A. Round House(水题)

    题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. CodeForces 489B BerSU Ball (水题 双指针)

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. C++之多态的一个例子

    [例12.1] 先建立一个Point(点)类,包含数据成员x,y(坐标点).以它为基类,派生出一个Circle(圆)类,增加数据成员r(半径),再以Circle类为直接基类,派生出一个Cylinder ...

  2. access的逻辑类型

    Alter TABLE [表名] ADD [新增字段] BOOLEAN或者Alter TABLE [表名] ADD [新增字段] YESNO 或者Alter TABLE [表名] ADD [新增字段] ...

  3. UISlider显示进度(并且实现图片缩放)

    图片展示效果如下: 其他没什么好说的,直接上代码: RootView.h: #import <UIKit/UIKit.h> @interface RootView : UIView @pr ...

  4. iOS闹钟实现

    UILocalNotification *notification=[[UILocalNotification alloc] init];         if (notification!=nil) ...

  5. 如何在自己的Windows系统上 架设服务器并开发网站,然后连入外网供外界访问?(JDK+Tomcat+花生壳)

    <目前百度谷歌上都木有我这么完整的笔记,虽然各个部分都是来自百度的,然后自己实践,自己做截图笔记,嘻嘻 Made By HeYang> 环境:Windows 7 工具:JDK,Apache ...

  6. fragment 切换

    1.Fragment的添加方式 FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.hide ft.show ft ...

  7. Memcache笔记03-php操作Memcached

    通过php程序操作Memcached服务几种形式 Memcache 扩展 Memcached 扩展 Socket套接字操作 memcached-client.php(函数) 对于php扩展来说,dan ...

  8. 2013MPD上海6.22 PM 陆宏杰:通往卓越管理的阶梯 & 6.23AM Ray Zhang 产品创新管理的十八般武艺

    MPD2天的内容,参加了5个课程,其中2个是管理的,分别是陆宏杰老师的<通往卓越管理的阶梯>和Ray Zhang大师的<产品创新管理的十八般武艺>.他们2个人都谈到了一个关于招 ...

  9. postfix删除队列中的邮件

    Postfix中有一套Mail Queue Management机制,所有队列中的邮件都可以全自动的处理,但在发送大量邮件的时候,有必要对这个队列进行手工的维护处理,比如说,删除队列中的邮件. 以下是 ...

  10. [转载]存储基础:DAS/NAS/SAN存储类型及应用

    这篇文章转自博客教主的一篇博客存储基础:DAS/NAS/SAN存储类型及应用, 他是在张骞的这篇博客DAS,NAS,SAN在数据库存储上的应用上做了部分修改和补充.   一. 硬盘接口类型 1. 并行 ...