A

  1. #include <bits/stdc++.h>
  2. #define PI acos(-1.0)
  3. #define mem(a,b) memset((a),b,sizeof(a))
  4. #define TS printf("!!!\n")
  5. #define pb push_back
  6. #define inf 1e9
  7. //std::ios::sync_with_stdio(false);
  8. using namespace std;
  9. //priority_queue<int,vector<int>,greater<int>> que; get min
  10. const double eps = 1.0e-10;
  11. const double EPS = 1.0e-4;
  12. typedef pair<int, int> pairint;
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. //const int maxn = 3e5 + 10;
  16. const int maxm = ;
  17. const int turn[][] = {{, }, { -, }, {, }, {, -}};
  18. //priority_queue<int, vector<int>, less<int>> que;
  19. //next_permutation
  20. ll mod = 3e7;
  21. const int maxn = ;
  22. int main()
  23. {
  24. int n, m;
  25. while (cin >> n >> m)
  26. {
  27. int mid = (n + m) / ;
  28. //cout<<mid<<endl;
  29. int x1 = abs(mid - n);
  30. int x2 = abs(m - mid);
  31. int ans = ( + x1) * x1 / + ( + x2) * x2 / ;
  32. cout << ans << endl;
  33. }
  34.  
  35. }

B

  1. #include <bits/stdc++.h>
  2. #define PI acos(-1.0)
  3. #define mem(a,b) memset((a),b,sizeof(a))
  4. #define TS printf("!!!\n")
  5. #define pb push_back
  6. #define inf 1e9
  7. //std::ios::sync_with_stdio(false);
  8. using namespace std;
  9. //priority_queue<int,vector<int>,greater<int>> que; get min
  10. const double eps = 1.0e-10;
  11. const double EPS = 1.0e-4;
  12. typedef pair<int, int> pairint;
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. //const int maxn = 3e5 + 10;
  16. const int turn[][] = {{, }, { -, }, {, }, {, -}};
  17. //priority_queue<int, vector<int>, less<int>> que;
  18. //next_permutation
  19. ll Mod = ;
  20. int main()
  21. {
  22. int n;
  23. cin >> n;
  24. int a, b;
  25. cin >> a >> b;
  26. if (a > b)
  27. {
  28. swap(a, b);
  29. }
  30. if (a <= n / && b > n / )
  31. {
  32. cout << "Final!" << endl;
  33. return ;
  34. }
  35. int anser = ;
  36. while (true)
  37. {
  38. a = (a + (a % )) / ;
  39. b = (b + (b % )) / ;
  40. if (a == b)
  41. {
  42. cout << anser << endl;
  43. return ;
  44. }
  45. anser++;
  46. }
  47. return ;
  48. }

C

  1. #include <bits/stdc++.h>
  2. #define PI acos(-1.0)
  3. #define mem(a,b) memset((a),b,sizeof(a))
  4. #define TS printf("!!!\n")
  5. #define pb push_back
  6. #define inf 1e9
  7. //std::ios::sync_with_stdio(false);
  8. using namespace std;
  9. //priority_queue<int,vector<int>,greater<int>> que; get min
  10. const double eps = 1.0e-10;
  11. const double EPS = 1.0e-4;
  12. typedef pair<int, int> pairint;
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. //const int maxn = 3e5 + 10;
  16. const int maxm = ;
  17. const int turn[][] = {{, }, { -, }, {, }, {, -}};
  18. //priority_queue<int, vector<int>, less<int>> que;
  19. //next_permutation
  20. ll mod = 3e7;
  21. const int maxn = ;
  22. int num[];
  23. int anser;
  24. int main()
  25. {
  26. int mx=-;
  27. int mn=;
  28. int mxnum=;
  29. int mnnum=;
  30. int n;
  31. cin >> n;
  32. anser=n;
  33. for(int i=; i<=n; i++)
  34. {
  35. scanf("%d",&num[i]);
  36. mx=max(mx,num[i]);
  37. mn=min(mn,num[i]);
  38. }
  39. if(mx-mn<=)
  40. {
  41. cout<<n<<endl;
  42. for(int i=; i<=n; i++)
  43. cout<<num[i]<<" ";
  44. cout<<endl;
  45. return ;
  46. }
  47. for(int i=; i<=n; i++)
  48. {
  49. if(num[i]==mx)
  50. mxnum++;
  51. else if(num[i]==mn)
  52. mnnum++;
  53. }
  54. int midnum=n-mxnum-mnnum;
  55. if(midnum/>=min(mxnum,mnnum))
  56. {
  57. int cur=midnum/;
  58. int cur1=cur;
  59. for(int i=; i<=n; i++)
  60. {
  61. if(num[i]==mn+&&cur)
  62. {
  63. anser--;
  64. num[i]--;
  65. cur--;
  66. continue;
  67. }
  68. if(num[i]==mn+&&cur1)
  69. {
  70. anser--;
  71. num[i]++;
  72. cur1--;
  73. continue;
  74. }
  75. }
  76. }
  77. else
  78. {
  79. int cur=min(mxnum,mnnum);
  80. int cur1=cur;
  81. for(int i=;i<=n;i++)
  82. {
  83. if(num[i]==mn&&cur)
  84. {
  85. num[i]++;
  86. anser--;
  87. cur--;
  88. continue;
  89. }
  90. if(num[i]==mx&&cur1)
  91. {
  92. num[i]--;
  93. anser--;
  94. cur1--;
  95. continue;
  96. }
  97. }
  98. }
  99. cout<<anser<<endl;
  100. for(int i=;i<=n;i++)
  101. cout<<num[i]<<" ";
  102. cout<<endl;
  103.  
  104. }

D

思维题 一层一层地消

  1. #include <bits/stdc++.h>
  2. #define PI acos(-1.0)
  3. #define mem(a,b) memset((a),b,sizeof(a))
  4. #define TS printf("!!!\n")
  5. #define pb push_back
  6. #define inf 1e9
  7. //std::ios::sync_with_stdio(false);
  8. using namespace std;
  9. //priority_queue<int,vector<int>,greater<int>> que; get min
  10. const double eps = 1.0e-10;
  11. const double EPS = 1.0e-4;
  12. typedef pair<int, int> pairint;
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. //const int maxn = 3e5 + 10;
  16. const int maxm = ;
  17. const int turn[][] = {{, }, { -, }, {, }, {, -}};
  18. //priority_queue<int, vector<int>, less<int>> que;
  19. //next_permutation
  20. ll mod = 3e7;
  21. const int maxn = ;
  22. int nextt[];
  23. int num[];
  24. int level[];
  25. int dp[];
  26. int anser = ;
  27. int main()
  28. {
  29. int n;
  30. cin >> n;
  31. dp[] = level[] = dp[] = ;
  32. for (int i = ; i <= n; i++)
  33. {
  34. scanf("%d", &nextt[i]);
  35. dp[i] = dp[nextt[i]] + ;
  36. level[dp[i]]++;
  37. }
  38. for(int i=;i<=;i++)
  39. {
  40. if(level[i]&)
  41. anser++;
  42. }
  43. cout<<anser<<endl;
  44. return ;
  45. }

E

状压DP

dp[i][j][k]表示第一个字母是i第二个字母是j距离为k有多少个

因为第一个字母是由第一个玩家定的 所以无法选择 第二个字母可以选择但只能最优地选一次 所以ans+=now 取所有长度里面概率最高的

  1. #include <bits/stdc++.h>
  2. #define PI acos(-1.0)
  3. #define mem(a,b) memset((a),b,sizeof(a))
  4. #define TS printf("!!!\n")
  5. #define pb push_back
  6. #define inf 1e9
  7. //std::ios::sync_with_stdio(false);
  8. using namespace std;
  9. //priority_queue<int,vector<int>,greater<int>> que; get min
  10. const double eps = 1.0e-10;
  11. typedef pair<int, int> pairint;
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14. //const int maxn = 3e5 + 10;
  15. const int maxn = ;
  16. const int turn[][] = {{, }, { -, }, {, }, {, -}};
  17. const int turn2[][] = {{, }, { -, }, {, }, {, -}, {, -}, { -, -}, {, }, { -, }};
  18. //priority_queue<int, vector<int>, less<int>> que;
  19. //next_permutation
  20. char a[];
  21. int dp[][][];
  22. int anser = ;
  23. int main()
  24. {
  25. scanf("%s", a + );
  26. int len = strlen(a + );
  27. for (int i = ; i <= len; i++)
  28. {
  29. a[i + len] = a[i];
  30. }
  31. for (int i = ; i <= len; i++)
  32. {
  33. for (int j = i + ; j < i + len; j++)
  34. {
  35. dp[a[i] - 'a'][a[j] - 'a'][j - i + ]++;
  36. }
  37. }
  38. int now = ;
  39. int cur;
  40. for (int i = ; i < ; i++)
  41. {
  42. now = ;
  43. for (int j = ; j <= len; j++)
  44. {
  45. cur = ;
  46. for (int k = ; k < ; k++)
  47. {
  48. if (dp[i][k][j] == )
  49. {
  50. cur++;
  51. }
  52. }
  53. now = max(now, cur);
  54. }
  55. anser += now;
  56. }
  57. printf("%.10f", (double)anser / len);
  58. return ;
  59. }

F

待补

Codeforces 931 概率DP的更多相关文章

  1. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  2. codeforces 148D 概率DP

    题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢. 王妃每次抓一仅仅老鼠,龙每次抓完一仅仅老鼠之后会有一仅仅老鼠跑出来. 每次抓老鼠和跑出来的老鼠都是随 ...

  3. codeforces 540D 概率dp

    传送门 大概可以这样理解, 一开始有r个石头, p个布, s个剪刀, 每一天有其中的两个相遇, 如果两个是相同的种类, 什么都不会发生, 否则的话有一个会挂掉, 问最后每一种生存的概率. dp[i][ ...

  4. CodeForces 398B 概率DP 记忆化搜索

    题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了 ...

  5. Codeforces - 518D 概率DP初步

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...

  6. Vasya and Magic Matrix CodeForces - 1042E (概率dp)

    大意:给定n*m矩阵, 初始位置(r,c), 每一步随机移动到权值小于当前点的位置, 得分为移动距离的平方, 求得分期望. 直接暴力dp的话复杂度是O(n^4), 把距离平方拆开化简一下, 可以O(n ...

  7. Broken robot CodeForces - 24D (概率DP)

    You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you unders ...

  8. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  9. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

随机推荐

  1. 【Spark机器学习速成宝典】基础篇02RDD常见的操作(Python版)

    目录 引例入门:textFile.collect.filter.first.persist.count 创建RDD的方式:parallelize.textFile 转化操作:map.filter.fl ...

  2. Python的datetime与Decimal数据进行json序列化的简单说明

    我们在Python的json.JSONEncoder类中可以查看Python数据序列化为JSON格式的数据时数据类型的对应关系: class JSONEncoder(object): "&q ...

  3. 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 ...

  4. [Web 前端] 026 jQuery 初探

    目录 1. jQuery 简介 2. jQuery 的简单操作 2.1 jQuery 选择器 2.1.1 简介 2.1.2 基础选择器 2.2 过滤获取 2.3 父子关系获取 3. jQuery 元素 ...

  5. [19/10/16-星期四] Python中的文件操作

    一.打开文件 # open(file, mode='r', buffering=-1, encoding_=None, errors=None, newline=None, closefd=True, ...

  6. tomcat启动失败的三种方法

    Tomcat启动失败的解决办法 1. 重复映射 用eclipse开发时,用Eclipse开发,新建了的servlet会有一个url-pattern声明: 这样就不需要再在web.xml中添加映射,如果 ...

  7. 取石子游戏 HDU 1527 博弈论 威佐夫博弈

    取石子游戏 HDU 1527 博弈论 威佐夫博弈 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两 ...

  8. [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会拉不下来.

  9. Linux下libaio的一个简单例子

    转载:http://www.cnblogs.com/aLittleBitCool/archive/2011/10/18/2216646.html 异步io,很好玩的一个东西,从接口来看,封装的比较厉害 ...

  10. Mysql中explain作用详解

    一.MYSQL的索引 1.索引(Index):帮助Mysql高效获取数据的一种数据结构.用于提高查找效率,可以比作字典.可以简单理解为排好序的快速查找的数据结构.2.索引的作用:便于查询和排序(所以添 ...