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

  1. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  2. Topcoder 好题推荐

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

随机推荐

  1. Introduction to 3D Game Programming with DirectX 11 翻译--开篇

    Direct3D 11简介 Direct3D 11是一个渲染库,用于在Windows平台上使用现代图形硬件编写高性能3D图形应用程序.Direct3D是一个windows底层库,因为它的应用程序编程接 ...

  2. nginx指令中的优化(配置文件)

    nginx指令中的优化(配置文件)worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数.worker_cpu_affinity 00000001 0000 ...

  3. 什么时候出现死锁,如何解决?mysql 引擎? 多个like or 查询sql如何优化?什么是常量池?for条件执行顺序

    1. 什么时候出现死锁,如何解决?mysql 引擎? 多个like or 查询sql如何优化? 资源竞争导致死锁,比如A B 同时操作两条记录,并等待对方释放锁. 优化sql, 加缓存,主从(如读写分 ...

  4. DB2 OLAP函数的使用

    说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...

  5. Django高级篇一RESTful架构及API设计

    一.什么是RESTful架构? 通过互联网通信,建立在分布式体系上"客户端/服务器模式”的互联网软件,具有高并发和高延时的特点. 简单的来说,就是用开发软件的模式开发网站.网站开发,完全可以 ...

  6. python的数字图像处理学习(2)

    图像的重定义大小,图像的缩扩,图像的旋转: from skimage import transform,data import matplotlib.pyplot as plt img = data. ...

  7. 762. Prime Number of Set Bits in Binary Representation

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  8. Linux服务器上新增开放端口号

    开放端口的方法: 方法一:命令行方式               1. 开放端口命令: /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT    ...

  9. 2019.02.06 bzoj2987: Earthquake(类欧几里得)

    传送门 题意简述:求满足ax+by+c≤0ax+by+c\le0ax+by+c≤0的二元组(x,y)(x,y)(x,y)对数. 思路: 类欧几里得算法模板题. 把式子变化一下变成:求满足0≤y≤−ax ...

  10. Linux未安装上传下载的插件,怎么进行文件的上传下载

    首先连上服务: 然后Alt+p,打开SFTp窗口: 例如,我们今天要往tomcat的webappmu目录下上传一个文件: 先pwd,查看我们Linux上所处的目录:pwd 然后进入到tomcat的we ...