题目连接

排行榜

A和I都是签到题

按位BFS K Yet Another Multiple Problem

题意:给一些可以用的数字,求最小的数,它由特定的数字组成且是n的倍数

分析:暴力枚举不可行,因为数字可能非常大。考虑到大数取模为0,BFS每一层即数位,递归输出路径。

  1. #include <bits/stdc++.h>
  2.  
  3. const int N = 1e4 + 5;
  4. bool no[10];
  5. std::pair<int, int> pre[N];
  6. int dir[10];
  7. bool vis[N];
  8. int n, m, tot;
  9.  
  10. void print(int u) {
  11. if (u != 0) {
  12. print (pre[u].first);
  13. printf ("%d", pre[u].second);
  14. }
  15. return ;
  16. }
  17.  
  18. void BFS() {
  19. memset (vis, false, sizeof (vis));
  20. std::queue<int> que;
  21. que.push (0);
  22. while (!que.empty ()) {
  23. int x = que.front (); que.pop ();
  24. for (int i=0; i<tot; ++i) {
  25. if (x == 0 && dir[i] == 0) {
  26. continue;
  27. }
  28. int y = (x * 10 + dir[i]) % n;
  29. if (y == 0) {
  30. print (x);
  31. printf ("%d\n", dir[i]);
  32. return ;
  33. }
  34. if (vis[y]) {
  35. continue;
  36. }
  37. vis[y] = true;
  38. pre[y] = std::make_pair (x, dir[i]);
  39. que.push (y);
  40. }
  41. }
  42. puts ("-1");
  43. return ;
  44. }
  45.  
  46. int main() {
  47. int cas = 0;
  48. while (scanf ("%d%d", &n, &m) == 2) {
  49. memset (no, false, sizeof (no));
  50. for (int i=0; i<m; ++i) {
  51. int x; scanf ("%d", &x);
  52. no[x] = true;
  53. }
  54. tot = 0;
  55. for (int i=0; i<10; ++i) {
  56. if (!no[i]) {
  57. dir[tot++] = i;
  58. }
  59. }
  60. printf ("Case %d: ", ++cas);
  61. BFS ();
  62. }
  63.  
  64. return 0;
  65. }

同类型的题目:

URAL 1495

  1. #include <bits/stdc++.h>
  2.  
  3. const int N = 1e6 + 5;
  4. std::pair<int, int> pre[N];
  5. bool vis[N];
  6. int n;
  7.  
  8. void print(int u) {
  9. if (u != 0) {
  10. print (pre[u].first);
  11. printf ("%d", pre[u].second);
  12. }
  13. return ;
  14. }
  15.  
  16. void BFS() {
  17. memset (vis, false, sizeof (vis));
  18. std::queue<int> que;
  19. que.push (0);
  20. while (!que.empty ()) {
  21. int x = que.front (); que.pop ();
  22. for (int i=1; i<3; ++i) {
  23. int y = (x * 10 + i) % n;
  24. if (y == 0) {
  25. print (x);
  26. printf ("%d\n", i);
  27. return ;
  28. }
  29. if (vis[y]) {
  30. continue;
  31. }
  32. vis[y] = true;
  33. pre[y] = std::make_pair (x, i);
  34. que.push (y);
  35. }
  36. }
  37. puts ("Impossible");
  38. return ;
  39. }
  40.  
  41. int main() {
  42. while (scanf ("%d", &n) == 1) {
  43. BFS ();
  44. }
  45.  
  46. return 0;
  47. }

HDOJ 1226

  1. #include <bits/stdc++.h>
  2.  
  3. const int N = 5e3 + 5;
  4. std::pair<int, int> pre[N];
  5. struct Node {
  6. int x, len;
  7. };
  8. int dir[16];
  9. bool vis[N];
  10. int n, c, m;
  11.  
  12. void print(int u) {
  13. if (u != 0) {
  14. print (pre[u].first);
  15. int x = pre[u].second;
  16. if (x < 10) {
  17. printf ("%d", x);
  18. } else {
  19. printf ("%c", 'A' + x - 10);
  20. }
  21. }
  22. return ;
  23. }
  24.  
  25. void BFS() {
  26. memset (vis, false, sizeof (vis));
  27. std::queue<Node> que;
  28. que.push ((Node) {0, 0});
  29. while (!que.empty ()) {
  30. Node &u = que.front (); que.pop ();
  31. if (u.len >= 500) {
  32. continue;
  33. }
  34. for (int i=0; i<m; ++i) {
  35. if (u.x == 0 && dir[i] == 0) {
  36. continue;
  37. }
  38. int y = (u.x * c + dir[i]) % n;
  39. if (y == 0) {
  40. print (u.x);
  41. int d = dir[i];
  42. if (d < 10) {
  43. printf ("%d\n", d);
  44. } else {
  45. printf ("%c\n", 'A' + d - 10);
  46. }
  47. return ;
  48. }
  49. if (vis[y]) {
  50. continue;
  51. }
  52. vis[y] = true;
  53. pre[y] = std::make_pair (u.x, dir[i]);
  54. que.push ((Node) {y, u.len + 1});
  55. }
  56. }
  57. puts ("give me the bomb please");
  58. return ;
  59. }
  60.  
  61. int main() {
  62. int T; scanf ("%d", &T);
  63. while (T--) {
  64. scanf ("%d%d", &n, &c);
  65. scanf ("%d", &m);
  66. char str[3];
  67. for (int i=0; i<m; ++i) {
  68. scanf ("%s", str);
  69. if (str[0] >= 'A' && str[0] <= 'F') {
  70. dir[i] = str[0] - 'A' + 10;
  71. } else {
  72. dir[i] = str[0] - '0';
  73. }
  74. }
  75. std::sort (dir, dir+m);
  76. if (n == 0) {
  77. if (dir[0] == 0) {
  78. puts ("0");
  79. } else {
  80. puts ("give me the bomb please");
  81. }
  82. } else {
  83. BFS ();
  84. }
  85. }
  86.  
  87. return 0;
  88. }

数学期望 B Candy

题意:两堆n个物品,每次拿走一个,从第一堆拿的概率p,另一堆概率1-p,问其中一堆0时,另一堆数量的期望。

分析:公式为:。p^n不好直接算,技巧:取对数后在exp阶乘回来

  1. #include <bits/stdc++.h>
  2.  
  3. //ret = sigma(exp(log(C(n+i, i) + (n+1) * log(p) + i * log(1-p))));
  4. double run(int n, double p) {
  5. double ret = 0, lp = log (p), lq = log (1-p), c = log (1.0);
  6. ret = exp (c + (n+1) * lp + 0 * lq) * n;
  7. for (int i=1; i<n; ++i) {
  8. c = c + log (n + i) - log (i);
  9. ret += exp (c + (n+1) * lp + i * lq) * (n - i);
  10. }
  11. return ret;
  12. }
  13.  
  14. int main() {
  15. int n, cas = 0; double p;
  16. while (scanf ("%d%lf", &n, &p) == 2) {
  17. printf ("Case %d: ", ++cas);
  18. if (p == 0 || p == 1) {
  19. printf ("%.8f\n", (double) n);
  20. } else {
  21. printf ("%.8f\n", run (n, p) + run (n, 1.0 - p));
  22. }
  23. }
  24. return 0;
  25. }

数论 J Exam

题意:定义f(x) = 满足x%(a*b)=0的pair(a,b)的数量,求f(1)+f(2)+f(3)+...+f(n)

分析:n<=10^11普通枚举不可行。转换一下,问题变成x=a*b*c的pair(a,b,c)的数量,设a<=b<=c,则a<=,b<=,枚举a和b,复杂度为O().还一个问题,题目求前缀总和,考虑pair(a,b)对1~n的贡献为n/(a*b),相当于1~n是a*b的倍数的个数。

  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long ll;
  4.  
  5. int sqrt2(ll x) {
  6. ll ret = (int) pow (1.0 * x, 0.5);
  7. while (ret * ret < x) {
  8. ret++;
  9. }
  10. while (ret * ret > x) {
  11. ret--;
  12. }
  13. return ret;
  14. }
  15.  
  16. int sqrt3(ll x) {
  17. ll ret = (int) pow (1.0 * x, 1.0 / 3);
  18. while (ret * ret * ret < x) {
  19. ret++;
  20. }
  21. while (ret * ret * ret > x) {
  22. ret--;
  23. }
  24. return ret;
  25. }
  26.  
  27. ll run(ll n) {
  28. ll sq3 = sqrt3 (n);
  29. ll ret = sq3; //a = b = c
  30. for (int i=1; i<=sq3; ++i) {
  31. ll ni = n / i;
  32. ll k = sqrt2 (ni);
  33. ret += (ni / i - i) * 3; //a = b < c
  34. ret += (k - i) * 3; //a < b = c
  35. for (int j=i+1; j<=k; ++j) {
  36. ret += (ni / j - j) * 6; //a < b < c
  37. }
  38. }
  39. return ret;
  40. }
  41.  
  42. int main() {
  43. ll n;
  44. int cas = 0;
  45. while (scanf ("%I64d", &n) == 1) {
  46. printf ("Case %d: %I64d\n", ++cas, run (n));
  47. }
  48. return 0;
  49. }

Regionals 2012 :: Chengdu的更多相关文章

  1. Regionals 2012 :: HangZhou

    题目传送门排行榜 一个人做了12年北大出的题,自己还是太弱了,图论的知识忘光光,最小生成树裸题写不来,Dijkstra TLE不知道用SPFA. 简单几何(点到线段的距离) + 三分 B Steali ...

  2. Regionals 2012 :: Asia - Dhaka

    水 B Wedding of Sultan 题意:求每个点的度数 分析:可以在,每个字母的的两个端点里求出的的出度,那么除了起点外其他点还有一个入度,再+1 /******************** ...

  3. 组队练习赛(Regionals 2012, North America - East Central NA)

    A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...

  4. [Regionals 2012 :: Asia - Tokyo ]

    链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=56 ...

  5. Regionals 2012, Asia - Jakarta 解题报告

    啥都不会做了.. 做题慢死 A.Grandpa's Walk 签到题. 直接DFS就行. 注意先判断这个点可以作为一个路径的起点不. 然后再DFS. 否则处理起来略麻烦 #include <io ...

  6. Regionals 2012, North America - Greater NY 解题报告

    这套题..除了几何的都出了 完全没时间学几何.杯具 A,B,J 水题不解释 C.Pen Counts 这题的话 写几个不等式限制边得范围就行了 然后枚举最小边 D.Maximum Random Wal ...

  7. 130825组队赛-Regionals 2012, North America - East Central NA

    A.Babs' Box Boutique 一道简单的dfs搜索题,需要两两比较,然后搜到底,得到最大值就行了.比赛时队友写的,我只负责debug..赛后自己写的.. #include<iostr ...

  8. UVALive 6177 The King's Ups and Downs

    The King's Ups and Downs Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UV ...

  9. HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)

    HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...

随机推荐

  1. Ajax如何使用Session

    在Ajax中有时会使用到Session,在aspx.cs文件这样获取: string name = Session["name"]; 但是在Ajax中就不能这样获取Session, ...

  2. HTML标记语法之图片Img元素

    语法:<img src=”xxx.jpg”alt=”xxx”title=”xxx”> 属性可取值如下: 属性名称 属性值 说明 src URL 图片路径 alt 文本 图片无法显示时的文本 ...

  3. Android笔记:去除标题栏

    1: 在oncreate方法中添加requestWindowFeature(Window.FEATURE_NO_TITLE); 必须在setContentView()之前执行. 2: 在Android ...

  4. *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext iOS9.1闪退问题解决

    错误原因在于 AppDelegate 中 didFinishLaunchingWithOptions 结束前 未定义 rootViewController,Xcode7规定必须要有rootViewCo ...

  5. 数据库支持emoji表情

    从MySQL5.5.3开始,MySQL 支持一种utf8mb4的字符集,这个字符集能够支持4字节的UTF8编码的字符.utf8mb4字符集能够完美地兼容utf8字符串.在数据存储方面,当一个普通中文字 ...

  6. Elasticsearch在Windows下的安装

    下载Elasticsearch,地址:elasticsearch.org/download 下载jdk,百度搜索jdk下载即可 配置JAVA_HOME变量,配置方法在此文:http://jingyan ...

  7. python中最简单的多进程程序

    学着.. #!/usr/bin/env python # -*- coding: utf-8 -*- # Spawn a Process: Chapter 3: Process Based Paral ...

  8. Visual Studio 2015的Web扩展包

    过去几年,Visual Studio扩展功能生态系统得到了蓬勃发展,社区贡献出了大量优秀的扩展,其中也包括大量针对Web开发的扩展.但是很多时候,感觉寻找.安装.更新好 几个扩展,总显得比较麻烦.如果 ...

  9. C# NamePipe使用小结

    最近在一次项目中使用到了C#中命名管道,所以在此写下一篇小结备忘. 为什么要使用命名管道呢?为了实现两个程序之间的数据交换.假设下面一个场景.在同一台PC上,程序A与程序B需要进行数据通信,此时我们就 ...

  10. 如何通过阅读C标准来解决C语言语法问题

    有时候必须非常专注地阅读ANSI C标准才能找到某个问题的答案.一位销售工程师把下面这段代码作为测试用例发给Sun的编译小组. foo(const char **p) {} int main(int ...