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 ...
随机推荐
- Java.WeakReference-SoftReference-PhantomReference
Weak Reference, Soft Reference, Phantom Reference 1. Introduction "Weak reference objects, whic ...
- 洛谷1312 Mayan游戏
原题链接 讨厌这种大搜索题 基本就是模拟搜索,注意细节即可. 以下是我用的两个剪枝: 将块向左移的前提是左边为空,因为该题要求先右后左,所以若左边有块,那么在上一次搜索向右移的时候一定会搜过,且字典序 ...
- 虚拟机安装centos7, 再安装gitlab 简单步骤
先安装Linux centos7(朋友贡献的. Linux官网有下) 我自己用vm安装的. 未出现特殊状况 gitlab的搭建 安装基础包 yum -y install curl policycore ...
- LocalStorage的一些使用
LocalStorage是什么 LocalStorage 是在Html5中出现的一种本地存储.说到本地存储,大家立马会联想到Cookie,还有SqlLite. LocalStorage 中的数据不会像 ...
- MySQL学习笔记-数据库文件
数据库文件 MySQL主要文件类型有如下几种 参数文件:my.cnf--MySQL实例启动的时候在哪里可以找到数据库文件,并且指定某些初始化参数,这些参数定义了某种内存结构的大小等设置,还介绍了参数类 ...
- Linux配置nodejs
http://my.oschina.net/blogshi/blog/260953 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码,一种是编译后的文件.我就是按照网上源 ...
- 【UI测试】--美观与协调性
- Windows 8.1 app 界面设计
大纲: Windows 应用商店应用 UI 详细信息 http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/dn263191.aspx 快 ...
- JS高级-Date- Error-***Function:
1. Date: API: 1. 8个单位: FullYear Month Date Day Hours Minutes Seconds Milliseconds 2. 每 ...
- 2018.12.08 codeforces 939E. Maximize!(二分答案)
传送门 二分答案好题. 题意简述:要求支持动态在一个数列队尾加入一个新的数(保证数列单增),查询所有子数列的 最大值减平均值 的最大值. 然而网上一堆高人是用三分做的. 我们先考虑当前的答案有可能由什 ...