gym 101170 NWERC 2016 H Hamiltonian Hypercube
来源:互联网 发布:淘宝店铺上架宝贝数量 编辑:程序博客网 时间:2024/06/01 10:40
Problem
Northwestern European Regional Contest 2016
vjudge.net/problem/Gym-101170H
Meaning
给出两个 n 位的格雷码,问它们只间隔者多少个码字(code word)
Analysis
格雷码只是 另一种编码方式,所以相当于问两个整数之间夹着多少个整数。将它转换成原码(得到真值)就很好处理。
- 原码转格雷码
int to_gray(int x){ return x ^= x >> 1;}
- 格雷码转原码
int to_binary(int x){ int y = x; while(x >>= 1) y ^= x; return y;}
Code
#include <cstdio>#include <algorithm>using namespace std;const int N = 60;char a[N+2], b[N+2];long long trans(char *s){ long long t = 0; for( ; *s; ++s) t = t << 1 | *s - '0'; // t = t * 2 + *s - '0' return t;}long long to_bin(long long g){ long long x = g; while(g >>= 1) x ^= g; return x;}int main(){ scanf("%*d %s %s", a, b); long long x = to_bin(trans(a)), y = to_bin(trans(b)); printf("%lld\n", max(x-y, y-x) - 1); return 0;}
阅读全文
0 0
- gym 101170 NWERC 2016 H Hamiltonian Hypercube
- 【GYM】101170H Hamiltonian Hypercube
- gym 101170 Problem H Hamiltonian Hypercube(找规律?)
- gym 101170 NWERC 2016 J Jupiter Orbiter
- gym 101170 NWERC 2016 A Arranging Hat
- gym 101170 NWERC 2016 I Iron and Coal
- GYM 100523H
- codeforces GYM 100792H
- Gym 100712H Bridges
- Gym 100947H-Phobia
- Gym - 100735H
- Gym-101490H
- Gym 101164.H
- Gym 101246.H
- Gym 101482.H
- Gym 100825 H
- Gym 101201.H
- Gym 101617H
- /*Oracle常用数据类型*/
- 【Linux】Linux下c++使用Json库
- android_音乐播放器
- C++之在资源管理类中提供对原始资源的访问(15)---《Effective C++》
- Tomcat学习总结(6)—— Tomcat集群配置
- gym 101170 NWERC 2016 H Hamiltonian Hypercube
- JS概念理解(一)——函数和对象、原型链、_proto_
- Openstack4J API初体验之浮动IP的查询,关联和删除
- HDOJ 1443 joseph (找规律)
- Android Studio解决unspecified on project app resolves to an APK archive which is not supported
- 反转链表
- Java基础知识总结(绝对经典)
- SpringMVC中跳转路径的问题
- 【工具】【idea】无法识别java文件(can't Resolve)