SRM472
这次是rng_58出的题目,思维难度还是相当大的的。。很值得一做。
250pt:
题意:盒子里有n 个 potatoes,甲乙两个人,每次只能拿4的幂次方数(1,4,16...),最后不能拿的输。求谁赢
思路:打表找规律。结果是n%5 == 2 || n % 5 == 0 后者赢。否则先者。
code:
#line 7 "PotatoGame.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int sg[]; class PotatoGame
{
public:
string theWinner(int n)
{
if (n % == || n % == ) return "Hanako";
return "Taro";
}
};
500pt:
题意:有N<=50张卡片,每张卡片有正方两面,现在题目给定每张卡片的正反两面上的数字(数字为1~n,并且每个数字出现两次),现在求把这n张卡片拿去排列,有多少种结果
思路:需要知道的知识:
1、有重复数字的排列:n个数字排列,其中有a个数字出现两次,排列数为:n!/2^a
2、对于一个长度为n的置换,取出k个数出现2次,有2*C(n, k*2)方案。
当然,出现置换解题的关键当然就是他了。。
对于1张卡片,将两边的数字连一条边,那么所有的卡片就会出现若干个环(也就是置换啦)
那么对于不同的环之间,是不会互相影响的,直接用乘法原理统计
难点的就是相同环之间,我们就必须枚举出现相同的数的个数,然后结合1和2进行统计即可。对了还要用到乘法逆元。。具体见代码吧。
code:
#line 7 "TwoSidedCards.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define M 1000000007
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
long long dp[][];
long long C[][];
int fa[]; class TwoSidedCards
{
public:
LL power(LL a, int b){
LL ret = ;
while (b){
if (b & ) ret = (ret * a) % M;
a = (a * a) % M;
b >>= ;
}
return ret;
}
int find(int k){
if (fa[k] == k) return k;
return fa[k] = find(fa[k]);
}
long long permCount(int n){
LL ret = ;
for (int i = ; i <= n; i += )
ret = (ret + C[n][i] * power(power(, i / - ), M - )) % M;
ret =(ret + C[n][]) % M;
for (int i = ; i <= n; ++i)
ret = (ret * i) % M;
return ret;
}
int theCount(vector <int> taro, vector <int> hanako)
{
for (int i = ; i <= ; ++i){
C[i][] = ;
for (int j = ; j <= i; ++j) C[i][j] = (C[i-][j-] + C[i-][j]) % M;
}
int n = taro.size(), m = taro.size();
for (int i = ; i <= n; ++i) fa[i] = i;
for (int i = ; i < n; ++i){
int x = taro[i], y = hanako[i];
int fx = find(x), fy = find(y);
if (fx != fy) fa[fx] = fy;
}
long long ret = ;
for (int i = ; i <= n; ++i) find(i);
for (int i = ; i <= n; ++i) if (fa[i] == i){
int s = ;
for (int j = ; j <= n; ++j)
if (fa[j] == i) ++s;
ret = (ret * C[m][s]) % M;
m -= s;
ret = (ret * permCount(s)) % M;
}
return ret;
}
};
code:
SRM472的更多相关文章
- Topcoder 好题推荐
SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...
随机推荐
- hdu 5491(2015合肥网赛)The Next
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5491 题意就是,T组测试数据.然后L,S1,S2.L的二进制中有x个1,x满足 S1<=x< ...
- spring boot (三): 热部署
介绍了Spring boot实现热部署的两种方式,这两种方法分别是使用 Spring Loaded和使用spring-boot-devtools进行热部署. 热部署是什么 大家都知道在项目开发过程中, ...
- MacDev.GarbageCollectionIsDeprecated-WhenXcodeCompileMacAppProject
Garbage Collection is not supported 当Xcode编译Mac OSX App时报错:"Garbage Collection is not supported ...
- There are stopped jobs
问题背景 系统:ubuntu,当输入exit退出shell时,出现There are stopped jobs 无法退出shell 解决办法 找到这个stopped job然后终止它 jobs 或者 ...
- flask 中文编码解码
process.append("中文") print(process) # return Response(json.dumps(process), mimetype='appli ...
- The prefix "mvc" for element "mvc:annotation-driven" is not bound 异常
https://www.cnblogs.com/maodot/p/7531042.html The prefix "mvc" for element "mvc:annot ...
- ros 编程习惯
1.设置ros的info,warning,debug,error等编写的时候要思考,何时该使用,以及在开头要使用设置rosconsole的级别来对应输出,以方便调试. 2.在使用ros_info等的时 ...
- 使用tensorflow下的GPU加速神经网络训练过程
下载CUDA8.0,安装 下载cuDNN v5.1安装.放置环境变量等. 其他版本就不装了.不用找其他版本的关系. 使用tensorflow-gpu1.0版本. 使用keras2.0版本. 有提示的. ...
- MyBatis中log4j 和 参数 和 分页和别名 功能
1.配置全局文件,注意各个配置标签的顺序 properties?, settings?, typeAliases?, typeHandlers?, objectFactory?, objectWr ...
- Neural Network Basics
在学习NLP之前还是要打好基础,第二部分就是神经网络基础. 知识点总结: 1.神经网络概要: 2. 神经网络表示: 第0层为输入层(input layer).隐藏层(hidden layer).输出层 ...