3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 72  Solved: 48[Submit][Status][Discuss] Description     贝茜和约翰在玩一个数字游戏.贝茜需要你帮助她.     游戏一共进行了G(1≤G≤100)场.第i场游戏开始于一个正整数Ni(l≤Ni≤1,000,000).游 戏规则是这样的:双方轮流操作,将当前的数字减去…
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using name…
一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define MAX 1000000bool b[MAX+2];int solve(){ for (in…
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 47  Solved: 32[Submit][Status] Description     贝茜和约翰在玩一个数字游戏.贝茜需要你帮助她.     游戏一共进行了G(1≤G≤100)场.第i场游戏开始于一个正整数Ni(l≤Ni≤1,000,000).游 戏规则是这样的:双方轮流操作,将当前的数字减去一个数,这个数可以…
#include<cstring> #include<cstdio> #include<algorithm> #include<set> using namespace std; int m,n; int SG[1000001]; int sg(int x) { if(SG[x]!=-1) return SG[x]; if(!x) return SG[x]=0; set<int>S; int maxv=0,minv=2147483647; int…
博弈论 Orz ZYF 从前往后递推……反正最大才10^6,完全可以暴力预处理每个数的状态是必胜还是必败(反正才两个后继状态),然后O(1)查询……我是SB /************************************************************** Problem: 3404 User: Tunix Language: C++ Result: Accepted Time:880 ms Memory:5180 kb ***********************…
1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 502  Solved: 432[Submit][Status] Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶牛们的分数均为0.如果N是奇数,那么奶牛就会把…
[算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不能贪心. 手写堆版本见http://www.cnblogs.com/onioncyc/p/6212840.html #include<cstdio> #include<algorithm> #include<queue> using namespace std; prior…
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶牛们的分数均为0.如果N是奇数,那么奶牛就会把它乘以3后再加1.如果N是偶数,那么这个数就会被除以2.数字每变动一次,这头奶牛就得到1分.当N的值等于1时,游戏结束,此时的分数就是这头奶牛在这局游戏中的最终得分. 以下是N的初始值为5时,一局游戏的完整过程: N 操作后所得数 注释 总分 5 16 3*5+1…
http://www.lydsy.com/JudgeOnline/problem.php?id=1666 这种我就不说了.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> using namespace std; #define rep(i, n) for(…
模拟 #include<iostream> #include<cstdio> using namespace std; int n,ans; int main() { scanf("%d",&n); for(;n>1;ans++) { if(n&1) n=n*3+1; else n>>=1; } printf("%d\n",ans); return 0; }…
本来以为是一道数学题,一顿XJBT导式子,结果就是个幼儿园都会的模拟. Code: #include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ll n; scanf("%lld",&n); int ans=0; for(;n>1;++ans){ if(n%2==0) n>>=1; else n=n*3+1; } printf("%d"…
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 41[Submit][Status] Description 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:   .一只奶牛加入队伍的左边(输入“AL”).   .一只奶牛加入队伍的…
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 60[Submit][Status] Description     农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来参加他的飞盘队.由于…
直接用STL的的deque就好了... ---------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<deque>   #define rep( i , n ) for( int i = 0 ; i &l…
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 129  Solved: 84[Submit][Status][Discuss] Description     农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来…
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 62[Submit][Status] Description 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:   .一只奶牛加入队伍的左边(输入“AL”).   .一只奶牛加入队伍的…
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3400 Description 农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来参加他的飞盘队.由于约翰的幸运数字是F(1≤F≤1000),他希望…
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players…
2703: Cow Digit Game Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte Total Submit: 1            Accepted:1 Description Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i start…
题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players alternate turns. On each turn, a player c…
描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players alternate turns. On each turn, a player can…
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 裸的双端队列.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using namespace std;…
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数的方案数. 题解: 表示状态: dp[i][j] = num of ways i:考虑到第i个数(还没选) j:之前所选数之和 MOD f == j 找出答案: ans = dp[n][0] - 1 不选也是一种方案,但题目种要求不能不选,所以-1. 如何转移: 选或不选第i个数. dp[i+1][…
太水了,背包DP. (转载请注明出处:http://www.cnblogs.com/Kalenda/) ; var n,f,i,j,ans,t,tt:longint; q:array[..] of longint; a:array[..,..] of longint; begin readln(n,f); to n do begin readln(q[i]); q[i]:=q[i] mod f; end; a[,]:=; to n do to f do a[i,j]:=(a[i-,(j-q[i]…
直接双端队列模拟,完了= = CODE: #include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<queue>using namespace std;int n,sum;char s[2],st[2];deque<int> d;int main(){ scanf("%d",&n); for (int i=1…
Description     农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来参加他的飞盘队.由于约翰的幸运数字是F(1≤F≤1000),他希望所有奶牛的飞盘水准指数之和是幸运数字的倍数.     帮约翰算算一共有多少种组队方式. Input     第1行输入N和F,之后N行输入Ri. Output       组队方式数模10^8取余的…
http://www.lydsy.com/JudgeOnline/problem.php?id=3400 既然是倍数我们转换成mod.. 设状态f[i][j]表示前i头牛modj的方案 那么答案显然是f[n][0] 其实这样就和背包差不多了,对于每个数 但是转移比较难理解?(自己好好想吧..) f[i][a%p]=1 (初始化自身状态 f[i][j]=f[i-1][j] (继承前边的状态 f[i][(j+a)%p]=(f[i][(j+a)%p]+f[i-1][j])从上一个阶段转移过来 #inc…
deque真的秀,queue和stack...没啥用了啊.操作差不多,就是在前面加一个front||back_就行了. 题干: 题目描述 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:   .一只奶牛加入队伍的左边(输入“AL”).   .一只奶牛加入队伍的右边(输入“AR”).   ·K只队伍左边奶牛离开(输入“DLK”).   ·K只队伍右边奶牛离开(输入“DRK”)…
1~9显然,后面平\(A\)过去 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a = (b); a <= (c); ++a) #define nR(a,b,c) for(register int a = (b); a >=…