Codeforces 577B Module Sum(分类讨论)
2016-02-11 23:17
381 查看
题意:
代码:
给你n个数,问你是否可以再里面选择一些,是的他们的和模m为0。 强行分类讨论。 1、当n>m时 这个时候,肯定可以得到n个连续的和,那么必定产生n个模m的值, 又因为n>m,那么肯定可以找到一个要求的值。 2、当n<=m时 因为m比较小,我们完全可以吧所有的可能只全部找出来,然后看 是否存在。
代码:
// // Created by CQU_CST_WuErli // Copyright (c) 2016 CQU_CST_WuErli. All rights reserved. // // #include<bits/stdc++.h> #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <stack> #include <set> #include <algorithm> #include <sstream> #define CLR(x) memset(x,0,sizeof(x)) #define OFF(x) memset(x,-1,sizeof(x)) #define MEM(x,a) memset((x),(a),sizeof(x)) #define For_UVa if (kase!=1) cout << endl #define BUG cout << "I am here" << endl #define lookln(x) cout << #x << "=" << x << endl #define SI(a) scanf("%d",&a) #define SII(a,b) scanf("%d%d",&a,&b) #define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c) #define rep(flag,start,end) for(int flag=start;flag<=end;flag++) #define Rep(flag,start,end) for(int flag=start;flag>=end;flag--) #define Lson l,mid,rt<<1 #define Rson mid+1,r,rt<<1|1 #define Root 1,n,1 #define BigInteger bign const int MAX_L=2005;// For BigInteger const int INF_INT=0x3f3f3f3f; const long long INF_LL=0x7fffffff; const int MOD=1e9+7; const double eps=1e-9; const double pi=acos(-1); typedef long long ll; using namespace std; int n,m; int a[1000100]; int main(int argc, char const *argv[]) { #ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout); #endif while(SII(n,m)==2) { rep(i,1,n) SI(a[i]); int flag=0; if (n>m) { int sum[1010]; set<int> st; CLR(sum); rep(i,1,n) { sum[i]=(sum[i-1]+a[i])%m; if (st.count(sum[i])) { flag=1;break; } st.insert(sum[i]); } } else { set<int> st; vector<int> v; for (int i=1;i<=n;i++) { int tmp=v.size(); for (int j=0;j<tmp;j++) { if (!st.count((a[i]+v[j])%m)) { v.push_back((a[i]+v[j])%m); st.insert((a[i]+v[j])%m); } } if (!st.count(a[i]%m)) st.insert(a[i]%m),v.push_back(a[i]%m); } if (st.count(0)) flag=1; } puts(flag?"YES":"NO"); } return 0; }
相关文章推荐
- 主动的阅读基础
- Mac使用svn
- Atitit.通过null 参数 反射 动态反推方法调用
- 【设计模式】1、抽象工厂模式
- Atitit.通过null 参数 反射 动态反推方法调用
- Atitit.通过null 参数 反射 动态反推方法调用
- 追逐梦想——毕业4年小记
- c语言:全系1000学生募捐,总数达到10万元结束,统计捐款人数,平均每人捐款数目
- 【Splay操作】续.....
- 面向对象思想
- 堆(Heap)
- async 异步进度条,防UI卡顿
- Codeforces 332B Maximum Absurdity(暴力)
- I - Long Distance Racing(第二季水)
- VS2015中cout、cin未声明的标识符错误的处理
- 111. Minimum Depth of Binary Tree LeetCode
- 基于MySQLi和jQuery的评论系统
- 225. Implement Stack using Queues LeetCode
- Codeforces 519D A and B and Interesting Substrings (简单hash)
- 【CodeForces 618C】Constellation