这次是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. python消息队列Queue

    实例1:消息队列Queue,不要将文件命名为"queue.py",否则会报异常"ImportError: cannot import name 'Queue'" ...

  2. [Robot Framework] 通过SikuliLibrary可以获取到图片,但是点击失效

    执行时,可以看到鼠标已经移动到图片上了,但是点击失效,日志也没有报错 后来发现是windows权限的问题. 通过打开Control Panel->System and Security-> ...

  3. 这一周~&&html+css的学习感悟

    一周一周过的很快,这个礼拜的学习状态并不是很好,好像每个月都有那么几天学习状态不怎么样.不知道是懈怠了还是怎么了…… 没有辜负上周一开始的目标,4.6号之前我就糊好了篇论文交了上去,不知道结果如何,希 ...

  4. 利用PHP脚本辅助MySQL数据库管理1-表结构

    <?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...

  5. NotificationMangerService处理显示通知

    设置——>应用——>点击“已下载”列表中的任一APP,如图:  代码位置:Settings\src\com\android\settings\applications\InstalledA ...

  6. mybatis学习五 log4j

    1.  log4j(log for java)由 apache 推出的开源免费日志处理的类库.2. 为什么需要日志: 2.1 在项目中编写 System.out.println();输出到控制台,当项 ...

  7. 45.UITableView去除分割线

    1.去除所有的分割线 table.separatorStyle = UITableViewCellSelectionStyleNone; 2.去除指定某一行的分割线 cell.separatorIns ...

  8. java.lang.SuppressWarnings的注解简介

    简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...

  9. 算法工程师B

    美团点评2017校招笔试真题-算法工程师B   1.以下关于经典的k-means聚类的说法哪个是错误的? A:k-means聚类算法是全局收敛的 B:k-means的聚类结果和初始聚类中心点的选取有关 ...

  10. hdu-1033(格式)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1033 参考文章:https://blog.csdn.net/curson_/article/detai ...