hdu5050_2014ACM上海__Divided Land
来源:互联网 发布:c语言define定义什么 编辑:程序博客网 时间:2024/06/05 11:29
本文出自:点击打开链接
原题见hdu5050
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <vector>#include <map>#include <algorithm>#include <queue>#include <cmath>#include <bitset>using namespace std;#define INF 0x3f3f3f3f#define ll long long int#define ui unsigned long#define ull unsigned long long #define MEM(a) memset(a, 0, sizeof(a))#define MEMM(a) memset(b, -1, sizeof(b))#define DBG(x, n) cout << (x) << " " << (n) << endl;#define SL(a) strlen(a)#define RS(s) scanf("%s", (s))#define PI(r) printf("%d\n", (r))#define RI(a) scanf("%d", &(a))#define RII(a, b) scanf("%d%d", &(a), &(b))#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))#ifdef ONLINE_JUDGE#define FOI(file) 0#define FOW(file) 0#else#define FOI(file) freopen(file,"r",stdin);#define FOW(file) freopen(file,"w",stdout);#endif#define N 1001bitset <1001> w;bitset <1001> h;bitset <1001> d;void bitsetSubtract(bitset<N> &x, const bitset<N> &y) { bool borrow = false; for (int i = 0; i < N; i++) { if (borrow) { if (x[i]) { x[i] = y[i]; borrow = y[i]; } else { x[i] = !y[i]; borrow = true; } } else { if (x[i]) { x[i] = !y[i]; borrow = false; } else { x[i] = y[i]; borrow = y[i]; } } }}bitset<N> gcd(bitset<N> u, bitset<N> v) { bitset<N> one (string("1")); bitset<N> zero (string("0")); int shift; if (u == 0) return v; if (v == 0) return u; for (shift = 0; ((u | v) & one) == zero; ++shift) { u >>= 1; v >>= 1; } while ((u & one) == zero) u >>= 1; do { while ((v & one) == zero) v >>= 1; string t1 = u.to_string<char, char_traits<char>, allocator<char> >(); string t2 = v.to_string<char, char_traits<char>, allocator<char> >(); if (t1 > t2) { bitset<N> t = v; v = u; u = t; } bitsetSubtract(v,u); } while (v != 0); return u << shift;}int main(){ //FOI("input"); //FOW("output"); //write your programme here int t; scanf("%d", &t); int i; int j; for(i = 1; i <= t; i++) { cin >> w >> h; d = gcd(w, h); printf("Case #%d: ", i); // cout << d << endl; j = 1000; while(d[j] != 1) j--; while(j != -1) { cout << d[j]; j --; } cout << endl; } return 0;}
0 0
- hdu5050_2014ACM上海__Divided Land
- hdu 5050 Divided Land---2014acm上海赛区网络赛
- 上海
- 上海
- 上海
- 上海
- 上海
- 上海。。
- Grass Land
- Prime Land
- Prime Land
- Prime Land
- Prime Land
- land attack
- Prime Land
- Land攻击
- Divided Land
- 居住用地 residential land
- 微信公众号全局返回码
- machine learning(线性回归)
- ASCII,UTF-8,Unicode字符串相互转换
- 中国最小黑客:为不做作业 黑掉学校系统
- 系统的进程通信(aidl)的实现原理
- hdu5050_2014ACM上海__Divided Land
- Android fragment
- 李亚鹏离婚前写给王菲的信疯传 内容矛盾
- 好长时间不看,php魔术变量又忘了,赶紧总结下
- 深入浅出Docker(一):Docker核心技术预览
- 二叉树的应用--哈夫曼树
- 孙红雷携女友珠宝店挑大钻戒 获VIP专属服务
- typedef
- Java IO中的文件复制实例(原创)