这次是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. 洛谷2860 [USACO06JAN]冗余路径Redundant Paths

    原题链接 题意实际上就是让你添加尽量少的边,使得每个点都在至少一个环上. 显然对于在一个边双连通分量里的点已经满足要求,所以可以用\(tarjan\)找边双并缩点. 对于缩点后的树,先讲下我自己的弱鸡 ...

  2. Java中关键字static的使用

    static 关键字 1).static只能修饰成员变量或成员方法,所有非静态是对象相关的,所有静态是类相关的. 2)被static修饰的成员变量成员方法独立于该类的任何对象,它不依赖类的特定的实例, ...

  3. UI设计教程分享:PS故障风海报制作教程

    1.首先找一张看起来很酷的图(也可以选择自己喜欢的图片):   2. 复制图层,点击添加图层样式,选择混合选项,在高级混合里面的通道选项,有R.G.B三个通道选项,默认是全部勾选的状态,选择其中一个勾 ...

  4. djiango控制语句

    {# 从0开始的索引#} {% for foo in value %} {# 从0开始的索引#} <p>{{ forloop.counter0 }}: {{ foo }}</p> ...

  5. mysql 设置用户并授权

    一, 创建用户: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指 ...

  6. js模态框实现原理

    <!DOCTYPE> <html> <head> <style>/* 定义模态对话框外面的覆盖层样式 */ #modal-overlay { visib ...

  7. jquery plugin 之 form表单验证插件

    基于h5表单验证系统.扩展了对easyui组件的支持 先上图: 提示样式用到了伪对象的 {content: attr(xxx)}函数方法,实现提示信息能动态切换. 1.关键属性说明: type: 表单 ...

  8. [html]Sublime Text添加插件

    今天想在Sublime Text(简称ST)内编写HTML后直接使用浏览器看效果,想添加View in Browser插件,然后遇到奇怪的问题添加插件直接报"找不到有用的插件" 一 ...

  9. SpringMVC 学习 十 SSM环境搭建(三)springMVC文件配置

    SpringMVC文件配置的详细过程,可以查看springMVC环境搭建的注解配置篇<springMVC学习三 注解开发环境搭建> <?xml version="1.0&q ...

  10. curl命令整理

    ##curl命令 curl命令是一个功能强大的网络工具,它能够通过http.ftp等方式下载文件,也能够上传文件. #####1. 下载单个文件,默认将输出打印到标准输出中(STDOUT)中``` c ...