翻硬币问题
来源:互联网 发布:seo研究中心是什么 编辑:程序博客网 时间:2024/05/17 03:53
一个数学问题
七枚硬币,每次翻两个,问能不能全部翻成正面
肯定不能
不管怎么翻 都是偶数个朝上
一开始也没细想
直接编程
顺便写了两个二进制模板吧
感觉和状态压缩也有一些联系
#include <iostream>#include <cstring>using namespace std;const int MAXN = 1<<7;bool b[MAXN];int a[7];void toarr(int x) { for (int i = 0; i < 7; i++) { a[i] = x % 2; x /= 2; }}int to2(){ int x = 0; for (int i = 0; i < 7; i++) { x += (a[i] << i); } return x;}void print(){ for (int i = 0; i < 7; i++) { cout << a[i]; } cout << endl;}void dfs(int x) { print(); for (int i = 0; i < 7; i++) { for (int j = 0; j < i; j++) { a[i] = 1 - a[i]; a[j] = 1 - a[j]; int t = to2(); if (!b[t]) { b[t] = true; dfs(to2()); } a[i] = 1 - a[i]; a[j] = 1 - a[j]; } }}int main(){ memset(b, 0, sizeof(b)); b[0] = true; dfs(0);}
0 0
- 翻硬币问题
- 翻硬币问题
- 翻硬币问题
- 翻硬币问题
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- 翻硬币
- [BZOJ100题留念]
- Android 6.0运行时权限
- 五步搞定Android开发环境部署
- 详解C中volatile关键字
- 高精度 hdu 2940 Hex Factorial
- 翻硬币问题
- Java开发岗位面试题归类
- POJ 2253
- Html Agility Pack基础类介绍及运用
- mysql 5.7 安装
- spark 中rdd与dataframe的合并
- Redis集群(主从配置)
- mysql联接和子查询的使用
- 上架你的应用从申请开发者账号开始