gdutProblem F: 我是好人4
来源:互联网 发布:2017嘉实基本面50 知乎 编辑:程序博客网 时间:2024/04/28 01:31
链接:http://gdutcode.sinaapp.com/problem.php?cid=1039&pid=5
题意:中文题。
分析:水容斥,因为才10^9所以最多能选9个数。直接dfs所以情况,加个剪枝mul>10^9即可。
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=10000010;const int MAX=151;const int mod=100000000;const int MOD1=100000007;const int MOD2=100000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=1000000000;const ll INF=10000000010;typedef double db;typedef unsigned long long ull;int k,a[60];ll ans;ll gcd(ll x,ll y) { return y ? gcd(y,x%y):x;}ll lcm(ll x,ll y) { return x/gcd(x,y)*y;}void dfs(int x,int g,ll mul) { if (mul>MOD) return ; if (x==k+1) { if (g&1) ans-=MOD/mul; else ans+=MOD/mul; return ; } dfs(x+1,g,mul); dfs(x+1,g+1,lcm(mul,a[x]));}int main(){ int i,j,n,t,bo; scanf("%d", &t); while (t--) { scanf("%d", &n); for (i=1;i<=n;i++) scanf("%d", &a[i]); sort(a+1,a+n+1); ans=0;k=0; for (i=1;i<=n;i++) { bo=0; for (j=k;j;j--) if (a[i]%a[j]==0) { bo=1;break ; } if (!bo) a[++k]=a[i]; } dfs(1,0,1ll); printf("%lld\n", ans); } return 0;}
1 0
- gdutProblem F: 我是好人4
- 广东工业大学2016校赛 Problem F: 我是好人4
- gdut 2016校赛决赛 Problem F我是好人4
- gudt 我是好人4
- GDUT 2016 Problem F 我是好人4 (容斥原理 + DFS)
- 我是好人
- 我是好人
- 我是个好人
- 我是个好人
- 我是一个好人
- GDUT决赛-我是好人
- GDUT决赛 我是好人
- 我是好人2
- GDUT1174:我是好人4(容斥定理)
- (初等数论)我是好人
- 因为我穷,所以我是好人
- 我是好人 【欧几里得定理的性质】
- 我是好人 【欧几里得定理的性质】
- 慢点走,我的时光
- js window对象方法属性整理
- Adapter(适配器)模式
- Keil中的中文字体乱码解决方法
- 日志
- gdutProblem F: 我是好人4
- Android中IntentService与Service的区别
- [线程]——线程阻塞
- 单向链表
- 巧用位运算 ZOJ 3870 Team Formation
- Problem C: 括号匹配(栈和队列)
- Facade(外观)模式
- Android中内存优化
- could not resolve all dependencies for configuration ' _debugcompile 错误