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的更多相关文章
随机推荐
- 201621123008 《Java程序设计》第十周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1. 常用异常 结合题集题目7-1回答 1.1 自己以前编写的代码中经常出现 ...
- Codeforces 749D. Leaving Auction set+二分
D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...
- RAC初步使用
信号基本流程: //1:创建信号 RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSub ...
- swift 判断真机还是模拟器
if Platform.isSimulator { // Do one thing print("isSimulator") } else { } struct Platform ...
- MySQL中的联结表
使用联结能够实现用一条SELECT语句检索出存储在多个表中的数据.联结是一种机制,用来在一条SELECT语句中关联表,不是物理实体,其在实际的数据库表中并不存在,DBMS会根据需要建立联结,且会在查询 ...
- MD5加密及Hash长度拓展攻击【通俗易懂】
先放一个简单点的利用了Hash长度拓展攻击的题目 if($COOKIE["getmein"] === md5($secret . urldecode($username . $pa ...
- SpringBoot中文乱码解决方案
转载:https://blog.csdn.net/wangshuang1631/article/details/70753801 方法一,修改application.properties文件 增加如下 ...
- Java第3章笔记
if基本语法: if(条件){// 表达式 // 代码块 } eg: int a = 10; if(a > 1){ System.out.println("内容& ...
- tp5框架成功、失败提示模板修改
<!DOCTYPE html> <html> <head> <title> 页面自动中...跳转 等待时间:<?php echo($wait); ...
- ACM-ICPC 2018 徐州赛区网络预赛 A Hard to prepare
https://nanti.jisuanke.com/t/31453 题目大意: 有n个人坐成一圈,然后有\(2^k\)种颜色可以分发给每个人,每个人可以收到相同的颜色,但是相邻两个人的颜色标号同或不 ...