这次是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的更多相关文章

  1. Topcoder 好题推荐

    SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...

随机推荐

  1. andorid 表格布局

    tablelayout.xml表格布局 <?xml version="1.0" encoding="utf-8"?> <TableLayout ...

  2. How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2

    This is how to set up Router or DHCP server for BMW KOMBI and NBT programming with Enet e sys cable ...

  3. 单细胞RNA测序技术之入门指南

    单细胞RNA测序技术之入门指南 [字体: 大 中 小 ] 时间:2018年09月12日 来源:生物通   编辑推荐: 在这个飞速发展的测序时代,DNA和RNA测序已经逐渐成为“实验室中的家常菜”.若要 ...

  4. delphi sdk 函数个数知多少?

    pascal用了这么久 那么您知道他有多少个函数,过程? 笔者统计了一下, delphi 7    21579个delphi xe2   41145个lazarus 1.12  70987个 ==== ...

  5. 繁体简体转化_langconv.py

    from copy import deepcopyimport re try: import psyco psyco.full()except: pass try: from zh_wiki impo ...

  6. PHP网站记录

    手把手教您搭建Apache下的PHP环境 http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E6%8E%A8%E8%8D%90/37371.sh ...

  7. idea+tomcat 端口占用

    ntelliJ IDEA和Tomcat整合注意事项(转) 这两天一直在学习IDEA这个开发工具,今天再整合tomcat的时候遇到了问题,运行时总是报错,说是8080端口被占用,把我就搞的郁闷了,我就尝 ...

  8. 超高清视频会议所需带宽分析---1M带宽应用720P是否可能?

    超高清视频会议所需带宽分析 ---1M带宽应用720P是否可能? 1.首先计算720P(1280×720)单幅图像照片的数据量 每像素用24比特表示,则:720P图像照片的原始数据量= 1280×72 ...

  9. android开发笔记(2)

    我之前完成了SDK的安装,这次需要在eclipse中导入相关的控件. 一.下载ADT 在之前下载的网站上下载相关的ADT的压缩包. 二.在eclipse中进行导入 在eclipse中的Help-> ...

  10. Servet-------JSTL标签库

    JSTL标签库 也可以和EL表达式配合使用 作用:   提高在Jsp中的逻辑代码的编写效率,使用标签..(对EL表达式的扩展)   使用: JSTL的核心标签库(重点) JSTL的SQL标签库 JST ...