codeforces 577B B. Modulo Sum(水题)
题目链接:
2 seconds
256 megabytes
standard input
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.
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).
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.
3 5
1 2 3
YES
1 6
5
NO
4 6
3 1 1 3
YES
6 6
5 5 5 5 5 5
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(水题)的更多相关文章
- 【CodeForces 577B】Modulo Sum
题 题意 给你n(1 ≤ n ≤ 106)个数a1..an(0 ≤ ai ≤ 109),再给你m( 2 ≤ m ≤ 103)如果n个数的子集的和可以被m整除,则输出YES,否则NO. 分析 分两种情况 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- [moka收藏]php正则表达式验证
手机号验证规则[['mobile'], 'match','pattern' =>"/^1[34578]\\d{9}$/"], [['sendmail_limit'],'mat ...
- Visual Studio添加dll程序集引用操作步骤
Visual Studio 中添加引用的操作: 在“解决方案资源管理器”中,先右击项目图标,在弹出菜单选择“添加引用...” 然后在弹出的窗口中选择所要添加的选项,点击确定就可以了. 原文:http: ...
- 对getElementsByTagName("*")获取全部元素的总结
var all=document.getElementsByTagName("*") //获取整个页面的标签元素 alert(all.length); ...
- Android studio 快捷添加构造方法以及set与get
第一种方式 快捷键: Alt + lnsert (笔记本可能没有后面的按键) 按快捷键会出现下面这个页面: 第二种方式:点开后是跳出上面那个选择框
- spring task定时器笔记
定时器有两种方式 1.延迟启动 <bean id="timerTaskRunnerChain" class="bingo.uam.task.TimerTaskRun ...
- Android Sqlite 实例入门
通过一个简单的例子来学习Sqlite,学生选课系统,一开始的需求是学生可以选课,选课完成后可以查询到已经选择的课. 首先设计三个表,学生,课程,选课.学生表存储学生的信息,课程表存储课程的信息,选课表 ...
- iOS沙盒简单介绍
先简单介绍一下什么是沙盒:你可以简单理解成为一个目录,这个目录的改动不会对操作系统造成任何损失.(这里也有一点点介绍) 看看苹果的沙盒目录: 再附一张苹果官方的图 一个iOS app操作都是在自己的沙 ...
- Web应用程序系统的多用户权限控制设计及实现-总述【1】
中大型的Web系统开发均需要权限的配置,基于多角色,多用户的操作权限管理是一个系统开发的基础.搭建好一套权限,用户,角色,页面一体的开发架构,可以用于后期业务的开发,同时也可用于不同业务的系统开发. ...
- swift如何动态创建对象
前言: 在一些大型的项目中常常在加载页面的时候根据服务器请求下来的数据动态创建视图控制器对象,最近的一个项目就有这一方面的需求,加载页面之前需要先请求服务器的数据得到一个JSON字典,根据里面字符串的 ...
- 多线程基础(三)NSThread基础
3.多线程基础 NSThread的基本使用 如何使用NSThread创建新线程 创建线程之后是默认不执行的状态 创建三个线程: 通过name属性区别这些线程 接下来就是通过设置线程的优先级来设 ...