Codeforces 931 概率DP
A
- #include <bits/stdc++.h>
- #define PI acos(-1.0)
- #define mem(a,b) memset((a),b,sizeof(a))
- #define TS printf("!!!\n")
- #define pb push_back
- #define inf 1e9
- //std::ios::sync_with_stdio(false);
- using namespace std;
- //priority_queue<int,vector<int>,greater<int>> que; get min
- const double eps = 1.0e-10;
- const double EPS = 1.0e-4;
- typedef pair<int, int> pairint;
- typedef long long ll;
- typedef unsigned long long ull;
- //const int maxn = 3e5 + 10;
- const int maxm = ;
- const int turn[][] = {{, }, { -, }, {, }, {, -}};
- //priority_queue<int, vector<int>, less<int>> que;
- //next_permutation
- ll mod = 3e7;
- const int maxn = ;
- int main()
- {
- int n, m;
- while (cin >> n >> m)
- {
- int mid = (n + m) / ;
- //cout<<mid<<endl;
- int x1 = abs(mid - n);
- int x2 = abs(m - mid);
- int ans = ( + x1) * x1 / + ( + x2) * x2 / ;
- cout << ans << endl;
- }
- }
B
- #include <bits/stdc++.h>
- #define PI acos(-1.0)
- #define mem(a,b) memset((a),b,sizeof(a))
- #define TS printf("!!!\n")
- #define pb push_back
- #define inf 1e9
- //std::ios::sync_with_stdio(false);
- using namespace std;
- //priority_queue<int,vector<int>,greater<int>> que; get min
- const double eps = 1.0e-10;
- const double EPS = 1.0e-4;
- typedef pair<int, int> pairint;
- typedef long long ll;
- typedef unsigned long long ull;
- //const int maxn = 3e5 + 10;
- const int turn[][] = {{, }, { -, }, {, }, {, -}};
- //priority_queue<int, vector<int>, less<int>> que;
- //next_permutation
- ll Mod = ;
- int main()
- {
- int n;
- cin >> n;
- int a, b;
- cin >> a >> b;
- if (a > b)
- {
- swap(a, b);
- }
- if (a <= n / && b > n / )
- {
- cout << "Final!" << endl;
- return ;
- }
- int anser = ;
- while (true)
- {
- a = (a + (a % )) / ;
- b = (b + (b % )) / ;
- if (a == b)
- {
- cout << anser << endl;
- return ;
- }
- anser++;
- }
- return ;
- }
C
- #include <bits/stdc++.h>
- #define PI acos(-1.0)
- #define mem(a,b) memset((a),b,sizeof(a))
- #define TS printf("!!!\n")
- #define pb push_back
- #define inf 1e9
- //std::ios::sync_with_stdio(false);
- using namespace std;
- //priority_queue<int,vector<int>,greater<int>> que; get min
- const double eps = 1.0e-10;
- const double EPS = 1.0e-4;
- typedef pair<int, int> pairint;
- typedef long long ll;
- typedef unsigned long long ull;
- //const int maxn = 3e5 + 10;
- const int maxm = ;
- const int turn[][] = {{, }, { -, }, {, }, {, -}};
- //priority_queue<int, vector<int>, less<int>> que;
- //next_permutation
- ll mod = 3e7;
- const int maxn = ;
- int num[];
- int anser;
- int main()
- {
- int mx=-;
- int mn=;
- int mxnum=;
- int mnnum=;
- int n;
- cin >> n;
- anser=n;
- for(int i=; i<=n; i++)
- {
- scanf("%d",&num[i]);
- mx=max(mx,num[i]);
- mn=min(mn,num[i]);
- }
- if(mx-mn<=)
- {
- cout<<n<<endl;
- for(int i=; i<=n; i++)
- cout<<num[i]<<" ";
- cout<<endl;
- return ;
- }
- for(int i=; i<=n; i++)
- {
- if(num[i]==mx)
- mxnum++;
- else if(num[i]==mn)
- mnnum++;
- }
- int midnum=n-mxnum-mnnum;
- if(midnum/>=min(mxnum,mnnum))
- {
- int cur=midnum/;
- int cur1=cur;
- for(int i=; i<=n; i++)
- {
- if(num[i]==mn+&&cur)
- {
- anser--;
- num[i]--;
- cur--;
- continue;
- }
- if(num[i]==mn+&&cur1)
- {
- anser--;
- num[i]++;
- cur1--;
- continue;
- }
- }
- }
- else
- {
- int cur=min(mxnum,mnnum);
- int cur1=cur;
- for(int i=;i<=n;i++)
- {
- if(num[i]==mn&&cur)
- {
- num[i]++;
- anser--;
- cur--;
- continue;
- }
- if(num[i]==mx&&cur1)
- {
- num[i]--;
- anser--;
- cur1--;
- continue;
- }
- }
- }
- cout<<anser<<endl;
- for(int i=;i<=n;i++)
- cout<<num[i]<<" ";
- cout<<endl;
- }
D
思维题 一层一层地消
- #include <bits/stdc++.h>
- #define PI acos(-1.0)
- #define mem(a,b) memset((a),b,sizeof(a))
- #define TS printf("!!!\n")
- #define pb push_back
- #define inf 1e9
- //std::ios::sync_with_stdio(false);
- using namespace std;
- //priority_queue<int,vector<int>,greater<int>> que; get min
- const double eps = 1.0e-10;
- const double EPS = 1.0e-4;
- typedef pair<int, int> pairint;
- typedef long long ll;
- typedef unsigned long long ull;
- //const int maxn = 3e5 + 10;
- const int maxm = ;
- const int turn[][] = {{, }, { -, }, {, }, {, -}};
- //priority_queue<int, vector<int>, less<int>> que;
- //next_permutation
- ll mod = 3e7;
- const int maxn = ;
- int nextt[];
- int num[];
- int level[];
- int dp[];
- int anser = ;
- int main()
- {
- int n;
- cin >> n;
- dp[] = level[] = dp[] = ;
- for (int i = ; i <= n; i++)
- {
- scanf("%d", &nextt[i]);
- dp[i] = dp[nextt[i]] + ;
- level[dp[i]]++;
- }
- for(int i=;i<=;i++)
- {
- if(level[i]&)
- anser++;
- }
- cout<<anser<<endl;
- return ;
- }
E
状压DP
dp[i][j][k]表示第一个字母是i第二个字母是j距离为k有多少个
因为第一个字母是由第一个玩家定的 所以无法选择 第二个字母可以选择但只能最优地选一次 所以ans+=now 取所有长度里面概率最高的
- #include <bits/stdc++.h>
- #define PI acos(-1.0)
- #define mem(a,b) memset((a),b,sizeof(a))
- #define TS printf("!!!\n")
- #define pb push_back
- #define inf 1e9
- //std::ios::sync_with_stdio(false);
- using namespace std;
- //priority_queue<int,vector<int>,greater<int>> que; get min
- const double eps = 1.0e-10;
- typedef pair<int, int> pairint;
- typedef long long ll;
- typedef unsigned long long ull;
- //const int maxn = 3e5 + 10;
- const int maxn = ;
- const int turn[][] = {{, }, { -, }, {, }, {, -}};
- const int turn2[][] = {{, }, { -, }, {, }, {, -}, {, -}, { -, -}, {, }, { -, }};
- //priority_queue<int, vector<int>, less<int>> que;
- //next_permutation
- char a[];
- int dp[][][];
- int anser = ;
- int main()
- {
- scanf("%s", a + );
- int len = strlen(a + );
- for (int i = ; i <= len; i++)
- {
- a[i + len] = a[i];
- }
- for (int i = ; i <= len; i++)
- {
- for (int j = i + ; j < i + len; j++)
- {
- dp[a[i] - 'a'][a[j] - 'a'][j - i + ]++;
- }
- }
- int now = ;
- int cur;
- for (int i = ; i < ; i++)
- {
- now = ;
- for (int j = ; j <= len; j++)
- {
- cur = ;
- for (int k = ; k < ; k++)
- {
- if (dp[i][k][j] == )
- {
- cur++;
- }
- }
- now = max(now, cur);
- }
- anser += now;
- }
- printf("%.10f", (double)anser / len);
- return ;
- }
F
待补
Codeforces 931 概率DP的更多相关文章
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- codeforces 148D 概率DP
题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢. 王妃每次抓一仅仅老鼠,龙每次抓完一仅仅老鼠之后会有一仅仅老鼠跑出来. 每次抓老鼠和跑出来的老鼠都是随 ...
- codeforces 540D 概率dp
传送门 大概可以这样理解, 一开始有r个石头, p个布, s个剪刀, 每一天有其中的两个相遇, 如果两个是相同的种类, 什么都不会发生, 否则的话有一个会挂掉, 问最后每一种生存的概率. dp[i][ ...
- CodeForces 398B 概率DP 记忆化搜索
题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了 ...
- Codeforces - 518D 概率DP初步
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...
- Vasya and Magic Matrix CodeForces - 1042E (概率dp)
大意:给定n*m矩阵, 初始位置(r,c), 每一步随机移动到权值小于当前点的位置, 得分为移动距离的平方, 求得分期望. 直接暴力dp的话复杂度是O(n^4), 把距离平方拆开化简一下, 可以O(n ...
- Broken robot CodeForces - 24D (概率DP)
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you unders ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
随机推荐
- 【Spark机器学习速成宝典】基础篇02RDD常见的操作(Python版)
目录 引例入门:textFile.collect.filter.first.persist.count 创建RDD的方式:parallelize.textFile 转化操作:map.filter.fl ...
- Python的datetime与Decimal数据进行json序列化的简单说明
我们在Python的json.JSONEncoder类中可以查看Python数据序列化为JSON格式的数据时数据类型的对应关系: class JSONEncoder(object): "&q ...
- httpd启动显示Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName'
AH00557: httpd: apr_sockaddr_info_get() failed for masterAH00558: httpd: Could not reliably determin ...
- [Web 前端] 026 jQuery 初探
目录 1. jQuery 简介 2. jQuery 的简单操作 2.1 jQuery 选择器 2.1.1 简介 2.1.2 基础选择器 2.2 过滤获取 2.3 父子关系获取 3. jQuery 元素 ...
- [19/10/16-星期四] Python中的文件操作
一.打开文件 # open(file, mode='r', buffering=-1, encoding_=None, errors=None, newline=None, closefd=True, ...
- tomcat启动失败的三种方法
Tomcat启动失败的解决办法 1. 重复映射 用eclipse开发时,用Eclipse开发,新建了的servlet会有一个url-pattern声明: 这样就不需要再在web.xml中添加映射,如果 ...
- 取石子游戏 HDU 1527 博弈论 威佐夫博弈
取石子游戏 HDU 1527 博弈论 威佐夫博弈 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两 ...
- [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Cannot access nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) in off
这个错误是将work offline打勾引起的. 这个是离线工作模式,相当于断网,远程的jar会拉不下来.
- Linux下libaio的一个简单例子
转载:http://www.cnblogs.com/aLittleBitCool/archive/2011/10/18/2216646.html 异步io,很好玩的一个东西,从接口来看,封装的比较厉害 ...
- Mysql中explain作用详解
一.MYSQL的索引 1.索引(Index):帮助Mysql高效获取数据的一种数据结构.用于提高查找效率,可以比作字典.可以简单理解为排好序的快速查找的数据结构.2.索引的作用:便于查询和排序(所以添 ...