SRM475
250pt:
题意:有最长N=17的一条格子,每个格子是W、B和R三种颜色之一,当某个格子上有兔子时,下一个回合该兔子按照以下的规则移动:
如果兔子在第一个格子,则向右移动一格;
否则如果兔子在倒数两个格子,则向左移动一格;
否则如果兔子在W格上,则向左移动一格;
否则如果兔子在B格上,则向右移动一格;
否则兔子在R格上,如果是它第一次移动,则向左移动一格,否则回到上一步过来的地方。
每一轮每个兔子移动,然后最后一个格子消失,如果某个格子上有多于一只兔子,则这个格子上的兔子消失。整个过程一直持续到总格子数等于2为止。现在在N个格子里面初始随机放R只兔子,问最后期望剩下几只兔子。
思路:模拟几个你会发现因为每回奇数位置的要跳到偶数位置,反之也一样。所以答案必然跟奇偶性有关系
很明显,奇数上的会相互抵消,偶数也一样。所以统计就很简单了。再者枚举一下初始位置即可。
code:
#line 7 "RabbitStepping.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 two(i) (1 << i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class RabbitStepping
{
public:
double getExpected(string field, int r)
{
int n = field.size();
int a, b;
double ret = ;
for (int i = ; i < two(n); ++i){
a = b = ;
for (int j = ; j < n; ++j) if (two(j) & i){
if (j & ) ++a;
else ++b;
}
if (a + b == r) ret += (a & ) + (b & );
}
for (int i = ; i <= r; ++i)
ret = ret / (n - i + 1.0) * (i + .);
return ret;
}
};
500pt
题意:第一年7月天上掉下一对小兔子;之后:
每年3月,老兔子生一对小兔子,原来的小兔子升级为老兔子;
某些年的11月,消失一半兔子,消失的兔子总是年龄较大的那些。
现在给定最多50个兔子会消失一半的年份,问第K<=10^7年的12月一共有多少兔子。答案模MOD=1,000,000,009。
思路:如果没有消失这一说,那么答案就是一个斐波那契数列。那就难在如何处理消失的。
而且每次%MOD后,再处理消失便会出问题。所以我们必须要用另外一个来记录奇偶性。
由于最多消失50次,也就是说最多有50次的/2操作。那么我们直接记录下当前答案%2^50的结果便可直到奇偶性。。
接下来直接模拟就行了。注意奇偶分开操作就行
code:
#line 7 "RabbitIncreasing.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 1000000009
#define P (1LL << 51)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class RabbitIncreasing
{
public:
long long power(long long a, int b){
long long ret = ;
for (;b > ; b >>= ){
if (b&) ret = (ret * a) % M;
a = (a * a) % M;
}
return ret;
}
int getNumber(vector <int> leave, int k)
{
sort(leave.begin(), leave.end());
int T2 = power(, M - );
long long cur = , pre = , next;
long long a = , b = , c;
long long dec, tmp;
if (leave[] == ) return ;
int l = , n = leave.size();
for (int i = ; i <= k; ++i){
next = (cur + pre) % M;
c = (a + b) % P;
if (l < n && leave[l] == i){
if (c & ){
dec = (c + ) / ;
c /= ;
a = (a - dec + P) % P;
tmp = ((next + ) * T2) % M;
cur = (cur - tmp + M) % M;
next = (next - tmp + M) % M;
}else {
dec = c / ;
c /= ;
a = (a - dec + P) % P;
tmp = (next * T2) % M;
cur = (cur - tmp + M) % M;
next = (next - tmp + M) % M;
}
++l;
}
pre = cur, cur = next;
b = a, a = c;
}
return cur;
}
};
SRM475的更多相关文章
- SRM475 - SRM479(1-250pt,500pt)
SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...
- Topcoder 好题推荐
SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...
随机推荐
- javascript 高级程序设计 十
理解JS对象(2)创建对象 JS中创建对象的方式有很多,我们把他们统称为模式. 工厂模式: 优点:解决了创建多个相似对象的问题. 缺点:没有解决对象识别问题.(不知道一个实例对象的类型) func ...
- grep如何进行正则表达式查找
字符类 字符类的搜索:如果我想要搜寻 test 或 taste 这两个单字时,可以发现到,其实她们有共通的 't?st' 存在-这个时候,我可以这样来搜寻: [root@www ~]# grep -n ...
- export export defalut
require/exports 和 import/export 形式不一样 require/exports 的用法只有以下三种简单的写法: const fs = require('fs') expor ...
- String... to 可变参数的使用
public class testMail { public static void fun(int... x) { for(int i = 0;i < x.length;i++) { Syst ...
- Sketch 和 PS中的设计图如何实现“自动切图”?
切图是很多UI设计师的一项日常工作.平时做完设计图,要将设计稿切成便于制作成页面的图片,并标注好尺寸和间距,交付给前端来完成html+css布局的静态页面,有利于交互,形成良好的视觉感. 但有的认为前 ...
- wcf 使用sqlMembership证书认证
.接口 namespace Aretch.WcfService.Services.Interface { [ServiceContract] public interface ICalculator ...
- Partition Array Into Three Parts With Equal Sum LT1013
Given an array A of integers, return true if and only if we can partition the array into three non-e ...
- centos7构建python2.7常用开发环境
把下面的代码保存到一个sh文件中执行即可 yum -y install epel-release yum -y install python-pip yum -y install mysql-deve ...
- SQL表两列取一列唯一值的记录
问下SQL表两列取一列唯一值的 A列 B列 C列 1001 AA 2012-01-02 1001 BB 2012-02-05 100 ...
- SLI的相关学习
今天帮人安装前年的机皇-微星GT80S的操作系统,安装好后用鲁大师测试下跑分,发现双显卡和单显卡鲁大师的跑分竟然一样,就像副显卡根本没有工作,听主人所这台机器能跑到36万以上. 然后就苦逼的尝试,把B ...