思路:模拟,set记录一下。

  1. #include<set>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7. set<int>se;
  8. int n,k,x,ans;
  9. int main(){
  10. freopen("del.in","r",stdin);
  11. freopen("del.out","w",stdout);
  12. scanf("%d%d",&n,&k);
  13. for(int i=;i<=n;i++){
  14. scanf("%d",&x);
  15. if(se.find(x)!=se.end()) k--;
  16. else{
  17. se.insert(x);
  18. ans++;
  19. }
  20. }
  21. if(k<=) cout<<ans<<endl;
  22. else cout<<ans-k<<endl;
  23. }

思路:搜索

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. using namespace std;
  8.  
  9. int board[][], isKing[][];
  10. int dir[][] = {{, }, {, -}, {-, }, {-, -}};
  11. int best_deep;
  12. vector<int> w;
  13. vector<int> ways;
  14.  
  15. void dfs(int step, int x, int y, int isKing)
  16. {
  17. w.push_back(x * + y);
  18. if (step > best_deep)
  19. {
  20. best_deep = step;
  21. ways.clear();
  22. ways.push_back(w[]);
  23. }
  24. else if (step > && step == best_deep)
  25. {
  26. ways.push_back(w[]);
  27. }
  28.  
  29. int dis_limit = isKing ? : ;
  30.  
  31. for (int d = ; d < ; d++)
  32. {
  33. bool pass = false;
  34. int passx = , passy = ;
  35. for (int dis = ; dis <= dis_limit; dis++)
  36. {
  37. int nxtX = x + dis * dir[d][];
  38. int nxtY = y + dis * dir[d][];
  39. if (!( <= nxtX && nxtX < && <= nxtY && nxtY < ))
  40. break;
  41. if (board[nxtX][nxtY] == || board[nxtX][nxtY] == )
  42. break;
  43. if (pass && board[nxtX][nxtY] == )
  44. break;
  45. if (board[nxtX][nxtY] == )
  46. {
  47. pass = true;
  48. passx = nxtX;
  49. passy = nxtY;
  50. }
  51. else
  52. {
  53. if (!pass)
  54. continue;
  55. board[passx][passy] = ;
  56. dfs(step + , nxtX, nxtY, isKing);
  57. board[passx][passy] = ;
  58. }
  59. }
  60. }
  61. w.pop_back();
  62. }
  63.  
  64. bool getAvailable()
  65. {
  66. ways.clear();
  67. w.clear();
  68. best_deep = ;
  69. for (int curX = ; curX < ; curX++)
  70. for (int curY = ; curY < ; curY++)
  71. if (board[curX][curY] == )
  72. dfs(, curX, curY, isKing[curX][curY]);
  73. if (best_deep == )
  74. {
  75. for (int curX = ; curX < ; curX++)
  76. for (int curY = ; curY < ; curY++)
  77. if (board[curX][curY] == )
  78. {
  79. if (isKing[curX][curY])
  80. {
  81. for (int x = curX + , y = curY + ; <= x && x < && <= y && y < ; x++, y++)
  82. if (!board[x][y])
  83. ways.push_back(curX * + curY);
  84. else
  85. break;
  86. for (int x = curX + , y = curY - ; <= x && x < && <= y && y < ; x++, y--)
  87. if (!board[x][y])
  88. ways.push_back(curX * + curY);
  89. else
  90. break;
  91. for (int x = curX - , y = curY + ; <= x && x < && <= y && y < ; x--, y++)
  92. if (!board[x][y])
  93. ways.push_back(curX * + curY);
  94. else
  95. break;
  96. for (int x = curX - , y = curY - ; <= x && x < && <= y && y < ; x--, y--)
  97. if (!board[x][y])
  98. ways.push_back(curX * + curY);
  99. else
  100. break;
  101. }
  102. else
  103. {
  104. if (curX - >= && curY - >= && !board[curX - ][curY - ])
  105. ways.push_back(curX * + curY);
  106. if (curX - >= && curY + < && !board[curX - ][curY + ])
  107. ways.push_back(curX * + curY);
  108. }
  109. }
  110. }
  111. if (!ways.size())
  112. return false;
  113. return true;
  114. }
  115.  
  116. int main(){
  117. freopen("chess.in", "r", stdin);
  118. freopen("chess.out", "w", stdout);
  119. memset(board, , sizeof(board));
  120. memset(isKing, , sizeof(isKing));
  121. for (int i = ; i < ; i++)
  122. for (int j = ; j < ; j++)
  123. {
  124. char c;
  125. scanf(" %c", &c);
  126. board[i][j] = c - '';
  127. }
  128. for (int i = ; i < ; i++)
  129. for (int j = ; j < ; j++)
  130. {
  131. char c;
  132. scanf(" %c", &c);
  133. isKing[i][j] = c - '';
  134. }
  135. getAvailable();
  136. if (!ways.size())
  137. printf("0\n");
  138. else {
  139. sort(ways.begin(), ways.end());
  140. printf("%d\n", (int)ways.size());
  141. for (int i = ; i < (int)ways.size(); i++)
  142. printf("(%d,%d)\n", ways[i] / + , ways[i] % + );
  143. }
  144. }

思路:状压DP.

对后续决策有影响的是什么?

现在已经吃了哪些馅饼

令F[i][s]表示考虑前i次馅饼掉落事件,吃了s这个二进制状态表示的馅饼,期望的美味值

对于每一次掉馅饼,枚举掉下来的馅饼是谁

若s&a[j]==a[j](a[j]为前提馅饼集合) F[i][s] -> F[i+1][s|(1<<(j-1))] 注意要 /n

递推的顺序?

一个起始状态,多个目标状态,正推会导致无效状态

反着推

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. int n,k,x,y;
  7. int w[],f[];
  8. double dp[][];
  9. int main(){
  10. freopen("bonus.in","r",stdin);
  11. freopen("bonus.out","w",stdout);
  12. scanf("%d%d",&n,&k);
  13. for(int i=;i<n;i++){
  14. scanf("%d",&w[i]);
  15. while(scanf("%d",&x)&&x) f[i]|=<<x-;
  16. }
  17. for(int s=;s<(<<n);s++) dp[k][s]=;
  18. for(int i=k-;i>=;i--)
  19. for(int s=;s<(<<n);s++)
  20. for(int j=;j<n;j++)
  21. if((s&f[j])==f[j]) dp[i][s]+=1.0/n*max(dp[i+][s],dp[i+][s|(<<j)]+w[j]);
  22. else dp[i][s]+=1.0/n*dp[i+][s];
  23. printf("%.6f\n",dp[][]);
  24. }

国庆 day 7 上午的更多相关文章

  1. 国庆 day 3 上午

    a[问题描述] 你是能看到第一题的 friends 呢. ——hja 怎么快速记单词呢?也许把单词分类再记单词是个不错的选择.何大爷给 出了一种分单词的方法,何大爷认为两个单词是同一类的当这两个单词的 ...

  2. 国庆 day 2 上午

    一道图论神题(god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只有 ...

  3. 国庆 day 6 上午

    1. 角谷猜想(kakutani.pas/c/cpp)(kakutani.in/out)时间限制:1s/空间限制:256M[题目描述] 某个名字末尾是 654321 的小 A 同学是个大家眼中公认的学 ...

  4. 2018国庆YALI集训游记

    想了想,像之前那样简略地叙述题意和做法,根本没讲清楚,没有任何意义,还不如写写自己的感受. 感觉YALI真的是一所挺不错的学校吧.总是能有一机房的julao轮番吊打你,总是能有集训队的奆佬来给你出dl ...

  5. SSH-Struts第三弹:传智播客视频教程第一天上午的笔记

    一. 框架概述1.三大框架 : 是企业主流 JavaEE 开发的一套架构 Struts2 + Spring + Hibernate 2. 什么是框架?为什么要学框架 ?框架 是 实现部分功能的代码 ( ...

  6. JAVA判断当前时间是上午am还是下午pm

    //结果为"0"是上午 结果为"1"是下午 public class GregorianTest { public static void main(Strin ...

  7. PKUSC 模拟赛 day2 上午总结

    今天上午考得不是很好,主要还是自己太弱QAQ 开场第一题给的图和题意不符,搞了半天才知道原来是走日字形的 然后BFS即可 #include<cstdio> #include<cstr ...

  8. PKUSC 模拟赛 day1 上午总结

    思考了一下第二题,觉得有无数种乱搞做法 类似什么bitset压位,MCS染色之类奇怪的做法 然而都是玄学正确性或者玄学复杂度 先放题解把 第一题显然具有单调性,二分就可以啦 O(nlogn),貌似输出 ...

  9. hihoCoder 1041 国庆出游 (DFS)

    题意: 小Hi和小Ho准备国庆期间去A国旅游.A国的城际交通比较有特色:它共有n座城市(编号1-n):城市之间恰好有n-1条公路相连,形成一个树形公路网.小Hi计划从A国首都(1号城市)出发,自驾遍历 ...

随机推荐

  1. 查看系统进程:ps、top

    1.ps命令:提供最近进程的快照.显示当前活跃进程的简要信息. 常见使用: (1)与grep命令配合查找是否有相应进程存活 ps -ef | grep ksmd ps -Af | grep ksmd ...

  2. Django - 表与ORM操作

    Django - 表与ORM操作 一. 模板语言 模板中也有自己的语言, 该语言可以实现数据展示 - {{ 变量 }} - 循环 {% for i in all_publisher %} {{ for ...

  3. Hdu 1429 胜利大逃亡(续) (bfs+状态压缩)

    这道题的钥匙只有10个,可以压成二进制 这里有有句非常关键的话 (k & door[x][y]) == door[x][y] 一开始以为只要(k & door[x][y]) ==1就可 ...

  4. JS中的NaN

    什么是NaN?它的类型是什么?如何可靠地测试一个值是否等于NaN? NaN属性表示“不是数字”的值.这个特殊值是由于一个操作数是非数字的(例如“abc”/ 4)或者因为操作的结果是非数字而无法执行的. ...

  5. php 魔术方法和魔术常量

    魔术方法:PHP把类中所有以__(两个下划线)开头的方法当成魔术方法,一般建议用户不要将自定义的方法前面加上__作为前缀.魔术方法: 1. __construct() 类的默认构造方法,如果__con ...

  6. ajax的两种使用方式

    一.Ajax概述 1.什么是同步,什么是异步 同步现象:客户端发送请求到服务器端,当服务器返回响应之前,客户端都处于等待 卡死状态 异步现象:客户端发送请求到服务器端,无论服务器是否返回响应,客户端都 ...

  7. Google翻译PDF文档

    Google翻译PDF文档 翻译软件虽多如牛毛,但有关整段/全文翻译,堪用的软件极少, 涉及专业技术的文献.胜任翻译工作的人力稀缺.少不了project师讴心沥血. 由于多是PDF格式.即使要翻译个概 ...

  8. C++字符串操作笔试题第二波

    //1.字符串替换空格:请实现一个函数,把字符串中的每一个空格替换成"%20". //比如输入"we are happy.".则输出"we%20are ...

  9. node11---相册

    app.js /* littleAlbum --.idea --controller(控制层相当于action层) --package.json --router.js --models(做事的是mo ...

  10. vim 按照字段排序文件

    假设有如下数据,以空格为数据列分割: 1  何维川   124.63     172  0.72 2  张子寅   99.67      172  0.58 3  周广滨   93.34      1 ...