上一页 1 ··· 80 81 82 83 84 85 86 87 88 ··· 182 下一页
摘要: 规律题题意:n个人站成一圈,从第一个人开始,每隔一个杀一个,问哪个人最后被杀。分析:虽然题目中认为这些人是站成一圈一杀到底,但是我们可以认为这些人是站成一排,每次从第二个活人开始,或者从第一个活人开始,从左到右每隔一个杀一个,直到只剩一个活人。如果我们每次给活人从1开始编号,那么每次从第二个杀,则每个活人的编号会变为(i - 1)/2+1,从第一个则变为i/2。最后剩一个编号为1的人。我们要做的就是记录每次从第几个开始杀,然后逆推,将编号为1的最后一个活人的编号按照刚才的规则,并根据每次从第一还是第二开始杀,逆推出其原编号。View Code #include <iostream> 阅读全文
posted @ 2011-09-01 10:42 undefined2024 阅读(256) 评论(0) 推荐(0)
摘要: 树状数组View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;#define maxn 30005struct Elem{ int a; int id;} elem[maxn];int n, m;int pos[maxn];int get[maxn];int ar[maxn];int lowb(int t){ return t & (-t) 阅读全文
posted @ 2011-09-01 09:31 undefined2024 阅读(219) 评论(0) 推荐(0)
摘要: 动态规划注意多解的情况View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 100long long value[maxn];char key[maxn], letter[maxn];long long f[maxn][maxn];int from[maxn][maxn];int l, k;int num[maxn];long long sum[maxn];void inp 阅读全文
posted @ 2011-08-31 19:18 undefined2024 阅读(178) 评论(0) 推荐(0)
摘要: 欧拉通路View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int n;char st[1005];bool exist[30];int in[30], out[30];int father[30];int getanc(int a){ if (father[a] == a) return a; return father[a] = getanc(father[a]);}void merge(in 阅读全文
posted @ 2011-08-31 15:37 undefined2024 阅读(231) 评论(0) 推荐(0)
摘要: 题意:一个01矩阵,表示灯的亮灭状态,每次操作可以改变一个十字形状内的五个灯的状态。问能否将所有灯熄灭。分析:高斯消元法对于每个灯的两灭有影响的开关就是它附近十字形内的五个开关。所以对于每个灯可以列一个方程,即周围五个开关异或起来的结果应该可以使该灯熄灭。就是利用线性代数知识,写出增广矩阵,化为阶梯形矩阵,有下到上依次解出各未知量。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>usingnamespace std;#define 阅读全文
posted @ 2011-08-31 15:04 undefined2024 阅读(1356) 评论(0) 推荐(0)
上一页 1 ··· 80 81 82 83 84 85 86 87 88 ··· 182 下一页