SRM467
250pt:
一个学生等老师来上课的,但是他不知道老师啥时候会来的,然后他等waiting时间后觉得无聊就会出去转walking时间,回来等待waiting时间后老师没来就会再次出去。老师会在a...b区间时间任意时刻来,是等概率的。但是老师等t时间后,就会不会让你进来了的。让你求你进不去教室的概率是多少。(所有的数<= 1000W)
思路:因为小于1000w,所以我就暴力把每一分钟的状态都统计出来。
注意长度为0的情况即可(比如老师即到即走的情况)举要特判
#line 7 "LateProfessor.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; class LateProfessor
{
public:
double getProbability(int wait, int walk, int late, int st, int end)
{
double sum = (end - st);
int m = wait + walk;
double ans = ;
// int last = -1, len = 0;
if (st == end){
if (st % m <= wait || (st % m > wait && st % m + late > m)) return 0.0;
return 1.0;
}
for (int i = st; i < end; ++i){
if (i % m < wait || (i % m >= wait && i % m + late >= m)) ++ans;
}
return - ans / sum;
} };
500pt:
给定supersum定义如下
- SuperSum(0 , n) = n, for all positive n.
- SuperSum(k , n) = SuperSum(k-1 , 1) + SuperSum(k-1 , 2) + ... + SuperSum(k-1 , n), for all positive k, n.
给定k,n(k <= 50, n <= 10^9),求supersum(k,n)
思路:乍一看不会做,然后就打了个20*20的表,发现斜着看就是一个杨辉三角,然后直接算可以了
答案就是C(n + k, k + 1)
#line 7 "SuperSum.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; class SuperSum
{
public:
long long power(long long a, long long b){
long long ret = ;
while (b){
if (b&) ret = (ret * a) % M;
b >>= ;
a = (a * a) % M;
}
return ret;
}
long long C(int n, int m){
long long ret = ;
for (int i = ; i <= m; ++i){
ret = (ret * power(i, M - )) % M;
ret = (ret * (n - i + )) % M;
}
return ret;
}
int calculate(int K, int N)
{
int n = K + N;
int m = K + ;
return C(n, m);
} };
SRM467的更多相关文章
随机推荐
- hdu 1558 (线段相交+并查集) Segment set
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1558 题意是在坐标系中,当输入P(注意是大写,我当开始就wa成了小写)的时候输入一条线段的起点坐标和终点坐 ...
- mount重新挂载为写模式
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system mount -o remount,rw -t rootfs rootfs /
- BZOJ 2733 [HNOI2012]永无乡 - 启发式合并主席树
Description 1: 查询一个集合内的K大值 2: 合并两个集合 Solution 启发式合并主席树板子 Code #include<cstdio> #include<cst ...
- mcu 通信数据解析
串口发送一帧数据时,两个字节的间隔时间是多少? 波特率:发送二进制数据位的速率,习惯上用 baud 表示,即我们发送一位二进制数据的持续时间=1/baud. 如果波特率为9600,发送一个位需要的时间 ...
- Python 之异常处理机制
python在程序运行出现错误时时有相应的反应机制 ,我们可以针对不同的错误做出不同的响应 list1 = ['a','b','c'] print(list1[4]) #>>>Ind ...
- 安装ubuntu16.04的时候出现的detecting file system
解决问题方法是,进入主界面执行,如下操作即可: sudo umount -l /isodevice
- Android中fragment之间和Activity的传值、切换
功能介绍:通过一个activity下方的三个按钮,分别是发送消息(sendButton).聊天记录(chatButton).常用语(commonButton).当单击按钮是,来切换上方的fragmen ...
- Controller异步模式
转载: https://blog.csdn.net/yingxiake/article/details/51193319 因为服务器请求处理线程的总数是有限的,如果类似的请求多了,所有的处理线程处于阻 ...
- PHP中=>是什么意思
一般用在php数组键名与元素的连接符如:$arr = array('a'=>'123','b'=>'456'); foreach($arr as $key=>$val){//$key ...
- AttributeError: type object 'testClass' has no attribute 'testMothod'
点击"Unittest for test_post_API.testClass"按钮,点击”Edit configuration...“,弹出对话框Run/Debug config ...