hdu 赛码1010 GCD
来源:互联网 发布:c语言static 编辑:程序博客网 时间:2024/06/07 00:18
GCD
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
n个数 q个已知区间的最大公约数 求出这n个数的值 是的这个n个数的和最小
直接构造 注意那个无解的判断
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 1010#define MAXM 100010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int Read(){ char ch; int a = 0; while((ch = getchar()) == ' ' | ch == '\n'); a += ch - '0'; while((ch = getchar()) != ' ' && ch != '\n') { a *= 10; a += ch - '0'; } return a;}void Print(int a){ if(a>9) Print(a/10); putchar(a%10+'0');}ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}ll l[MAXN],r[MAXN],a[MAXN];ll b[MAXN];int main(){// fread; int tc; scanf("%d",&tc); while(tc--) { int n,q; scanf("%d%d",&n,&q); for(int i=0;i<q;i++) scanf("%I64d%I64d%I64d",&l[i],&r[i],&a[i]); int flag=0; for(int i=0;i<q;i++) for(int j=i+1;j<q;j++) { if((l[j]>=l[i]&&r[j]<=r[i]&&a[j]<a[i])||(l[j]<=l[i]&&r[j]>=r[i]&&a[j]>a[i])) { flag=1; } } if(flag) { puts("Stupid BrotherK!"); continue; } for(int i=1;i<=n;i++) b[i]=1; for(int i=0;i<q;i++) { for(int j=l[i];j<=r[i];j++) { if(a[i]%b[j]==0) { b[j]=a[i]; } else { ll tmp=(a[i]*b[j])/gcd(a[i],b[j]); b[j]=tmp; } } } for(int i=1;i<=n;i++) { if(i>1) printf(" "); printf("%I64d",b[i]); } puts(""); } return 0;}
0 0
- hdu 赛码1010 GCD
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- GCD HDU
- hdu--1787---gcd again
- hdu 1787 GCD again
- HDU 1695 GCD 数论
- HDU 2588 GCD
- hdu-又见GCD
- hdu 1695 GCD
- hdu 1695 GCD
- C++运算符重载,+-*/的重载,返回值为什么是对象而不是对象的引用?而流操作符<< 和 >> 却返回的是引用?
- 安卓面试一
- Java中的参数传递方式
- ZOJ Problem Set - 1151||Word Reversal
- Android中manifest中的属性们
- hdu 赛码1010 GCD
- MariaDB 数据库还原
- 配置Log4j(很详细)
- Road constructions (hdu 3917 最大权闭合图)
- 开始充电学习
- [C++]LeetCode 26: Remove Duplicates from Sorted Array(有序数组去重)
- 关于未完全Root的Android系统如何彻底ROOT
- 跨域post方式传递数据解决方案--CORS
- Linux 环境实现ping攻击