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同学笔记]yii2.0数据库操作以及分页
1.model中models/article.php 1 <?php 2 3 namespace app\models; 4 5 use Yii; 6 7 /** 8 * This is the ...
- 如何使用mybatis《二》
前边阐述了如何在java项目中使用mybatis,我们使用的是映射文件的方式,在获得具体的数据操作方法时需要传入映射文件中namespace+“.”方法名称,这种方式有时候会感觉很不爽,很麻烦.我们在 ...
- linux backlog深入剖析以及netty设置backlog
netty不同于socket,其上次API没有提供设置backlog的选项,而是依赖于操作系统的somaxconn和tcp_max_syn_backlog,对于不同OS或版本,该值不同,建议根据实际并 ...
- 使用Apache ab进行压力测试(参数说明)
我们一般会使用Apache自带的ab来对项目进行压力测试,看项目的执行情况如何. 我们可以使用 ab -v 来查看ab的详细参数使用方法. [root@node234 bin]# ./ab -v ab ...
- 基于流的自动化构建工具------gulp (简单配置)
项目上线也有一阵子,回头过来看了看从最初的项目配置到开发的过程,总有些感慨,疲软期,正好花点时间,看看最初的配置情况 随着前端的发展,前端工程化慢慢成为业内的主流方式,项目开发的各种构建工具,也出现了 ...
- 字母排序问题(c++实现)
描述:编写一个程序,当输入不超过60个字符组成的英文文字时,计算机将这个句子中的字母按英文字典字母顺序重新排列,排列后的单词的长度要与原始句子中的长度 相同.例如: 输入: THE PRICE OFB ...
- SAPScript、Smartforms动态打印图像或者背景图片
在利用 SMARTFORMS 进行打印的时候有时候要求输出的图片可能是随着打印内容的不同而不同了,也就是动态输出图片,SMARTFORMS的提供了相关的支持技术,下面是实现截图 1.创建要显示的图片 ...
- 使用NPOI将多张图片导入execl
protected void btn_Export_Click(object sender, EventArgs e) { List<BNXX_SJXJ_XJSJ> list = View ...
- IOS字典NSDictionary与NSMutableDictionary知识点
字典中的元素是以键值对的形式存储的,键值对的键和值,都是任意的对象,但是键往往使用字符串,字典存储对象的地址没有顺序,字典的遍历分为:键的遍历和值的遍历,字典与数组的区别:数组讲究顺序,而字典可以快速 ...
- 如何轻松实现iOS9多任务管理器效果(iCarousel高级教程)
前言 iOS9系统下 为了我司APP的兼容性问题 特意把手上的iOS Mac XCode都升级到了最新的beta版 然后发现iOS9的多任务管理器风格大变 变成了下面这种样子 我忽然想起来之前的文章提 ...