Regionals 2012 :: Chengdu
A和I都是签到题
按位BFS K Yet Another Multiple Problem
题意:给一些可以用的数字,求最小的数,它由特定的数字组成且是n的倍数
分析:暴力枚举不可行,因为数字可能非常大。考虑到大数取模为0,BFS每一层即数位,递归输出路径。
- #include <bits/stdc++.h>
- const int N = 1e4 + 5;
- bool no[10];
- std::pair<int, int> pre[N];
- int dir[10];
- bool vis[N];
- int n, m, tot;
- void print(int u) {
- if (u != 0) {
- print (pre[u].first);
- printf ("%d", pre[u].second);
- }
- return ;
- }
- void BFS() {
- memset (vis, false, sizeof (vis));
- std::queue<int> que;
- que.push (0);
- while (!que.empty ()) {
- int x = que.front (); que.pop ();
- for (int i=0; i<tot; ++i) {
- if (x == 0 && dir[i] == 0) {
- continue;
- }
- int y = (x * 10 + dir[i]) % n;
- if (y == 0) {
- print (x);
- printf ("%d\n", dir[i]);
- return ;
- }
- if (vis[y]) {
- continue;
- }
- vis[y] = true;
- pre[y] = std::make_pair (x, dir[i]);
- que.push (y);
- }
- }
- puts ("-1");
- return ;
- }
- int main() {
- int cas = 0;
- while (scanf ("%d%d", &n, &m) == 2) {
- memset (no, false, sizeof (no));
- for (int i=0; i<m; ++i) {
- int x; scanf ("%d", &x);
- no[x] = true;
- }
- tot = 0;
- for (int i=0; i<10; ++i) {
- if (!no[i]) {
- dir[tot++] = i;
- }
- }
- printf ("Case %d: ", ++cas);
- BFS ();
- }
- return 0;
- }
同类型的题目:
URAL 1495
- #include <bits/stdc++.h>
- const int N = 1e6 + 5;
- std::pair<int, int> pre[N];
- bool vis[N];
- int n;
- void print(int u) {
- if (u != 0) {
- print (pre[u].first);
- printf ("%d", pre[u].second);
- }
- return ;
- }
- void BFS() {
- memset (vis, false, sizeof (vis));
- std::queue<int> que;
- que.push (0);
- while (!que.empty ()) {
- int x = que.front (); que.pop ();
- for (int i=1; i<3; ++i) {
- int y = (x * 10 + i) % n;
- if (y == 0) {
- print (x);
- printf ("%d\n", i);
- return ;
- }
- if (vis[y]) {
- continue;
- }
- vis[y] = true;
- pre[y] = std::make_pair (x, i);
- que.push (y);
- }
- }
- puts ("Impossible");
- return ;
- }
- int main() {
- while (scanf ("%d", &n) == 1) {
- BFS ();
- }
- return 0;
- }
HDOJ 1226
- #include <bits/stdc++.h>
- const int N = 5e3 + 5;
- std::pair<int, int> pre[N];
- struct Node {
- int x, len;
- };
- int dir[16];
- bool vis[N];
- int n, c, m;
- void print(int u) {
- if (u != 0) {
- print (pre[u].first);
- int x = pre[u].second;
- if (x < 10) {
- printf ("%d", x);
- } else {
- printf ("%c", 'A' + x - 10);
- }
- }
- return ;
- }
- void BFS() {
- memset (vis, false, sizeof (vis));
- std::queue<Node> que;
- que.push ((Node) {0, 0});
- while (!que.empty ()) {
- Node &u = que.front (); que.pop ();
- if (u.len >= 500) {
- continue;
- }
- for (int i=0; i<m; ++i) {
- if (u.x == 0 && dir[i] == 0) {
- continue;
- }
- int y = (u.x * c + dir[i]) % n;
- if (y == 0) {
- print (u.x);
- int d = dir[i];
- if (d < 10) {
- printf ("%d\n", d);
- } else {
- printf ("%c\n", 'A' + d - 10);
- }
- return ;
- }
- if (vis[y]) {
- continue;
- }
- vis[y] = true;
- pre[y] = std::make_pair (u.x, dir[i]);
- que.push ((Node) {y, u.len + 1});
- }
- }
- puts ("give me the bomb please");
- return ;
- }
- int main() {
- int T; scanf ("%d", &T);
- while (T--) {
- scanf ("%d%d", &n, &c);
- scanf ("%d", &m);
- char str[3];
- for (int i=0; i<m; ++i) {
- scanf ("%s", str);
- if (str[0] >= 'A' && str[0] <= 'F') {
- dir[i] = str[0] - 'A' + 10;
- } else {
- dir[i] = str[0] - '0';
- }
- }
- std::sort (dir, dir+m);
- if (n == 0) {
- if (dir[0] == 0) {
- puts ("0");
- } else {
- puts ("give me the bomb please");
- }
- } else {
- BFS ();
- }
- }
- return 0;
- }
数学期望 B Candy
题意:两堆n个物品,每次拿走一个,从第一堆拿的概率p,另一堆概率1-p,问其中一堆0时,另一堆数量的期望。
分析:公式为:。p^n不好直接算,技巧:取对数后在exp阶乘回来
- #include <bits/stdc++.h>
- //ret = sigma(exp(log(C(n+i, i) + (n+1) * log(p) + i * log(1-p))));
- double run(int n, double p) {
- double ret = 0, lp = log (p), lq = log (1-p), c = log (1.0);
- ret = exp (c + (n+1) * lp + 0 * lq) * n;
- for (int i=1; i<n; ++i) {
- c = c + log (n + i) - log (i);
- ret += exp (c + (n+1) * lp + i * lq) * (n - i);
- }
- return ret;
- }
- int main() {
- int n, cas = 0; double p;
- while (scanf ("%d%lf", &n, &p) == 2) {
- printf ("Case %d: ", ++cas);
- if (p == 0 || p == 1) {
- printf ("%.8f\n", (double) n);
- } else {
- printf ("%.8f\n", run (n, p) + run (n, 1.0 - p));
- }
- }
- return 0;
- }
数论 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的倍数的个数。
- #include <bits/stdc++.h>
- typedef long long ll;
- int sqrt2(ll x) {
- ll ret = (int) pow (1.0 * x, 0.5);
- while (ret * ret < x) {
- ret++;
- }
- while (ret * ret > x) {
- ret--;
- }
- return ret;
- }
- int sqrt3(ll x) {
- ll ret = (int) pow (1.0 * x, 1.0 / 3);
- while (ret * ret * ret < x) {
- ret++;
- }
- while (ret * ret * ret > x) {
- ret--;
- }
- return ret;
- }
- ll run(ll n) {
- ll sq3 = sqrt3 (n);
- ll ret = sq3; //a = b = c
- for (int i=1; i<=sq3; ++i) {
- ll ni = n / i;
- ll k = sqrt2 (ni);
- ret += (ni / i - i) * 3; //a = b < c
- ret += (k - i) * 3; //a < b = c
- for (int j=i+1; j<=k; ++j) {
- ret += (ni / j - j) * 6; //a < b < c
- }
- }
- return ret;
- }
- int main() {
- ll n;
- int cas = 0;
- while (scanf ("%I64d", &n) == 1) {
- printf ("Case %d: %I64d\n", ++cas, run (n));
- }
- return 0;
- }
Regionals 2012 :: Chengdu的更多相关文章
- Regionals 2012 :: HangZhou
题目传送门排行榜 一个人做了12年北大出的题,自己还是太弱了,图论的知识忘光光,最小生成树裸题写不来,Dijkstra TLE不知道用SPFA. 简单几何(点到线段的距离) + 三分 B Steali ...
- Regionals 2012 :: Asia - Dhaka
水 B Wedding of Sultan 题意:求每个点的度数 分析:可以在,每个字母的的两个端点里求出的的出度,那么除了起点外其他点还有一个入度,再+1 /******************** ...
- 组队练习赛(Regionals 2012, North America - East Central NA)
A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...
- [Regionals 2012 :: Asia - Tokyo ]
链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=56 ...
- Regionals 2012, Asia - Jakarta 解题报告
啥都不会做了.. 做题慢死 A.Grandpa's Walk 签到题. 直接DFS就行. 注意先判断这个点可以作为一个路径的起点不. 然后再DFS. 否则处理起来略麻烦 #include <io ...
- Regionals 2012, North America - Greater NY 解题报告
这套题..除了几何的都出了 完全没时间学几何.杯具 A,B,J 水题不解释 C.Pen Counts 这题的话 写几个不等式限制边得范围就行了 然后枚举最小边 D.Maximum Random Wal ...
- 130825组队赛-Regionals 2012, North America - East Central NA
A.Babs' Box Boutique 一道简单的dfs搜索题,需要两两比较,然后搜到底,得到最大值就行了.比赛时队友写的,我只负责debug..赛后自己写的.. #include<iostr ...
- 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 ...
- 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 ...
随机推荐
- Ajax如何使用Session
在Ajax中有时会使用到Session,在aspx.cs文件这样获取: string name = Session["name"]; 但是在Ajax中就不能这样获取Session, ...
- HTML标记语法之图片Img元素
语法:<img src=”xxx.jpg”alt=”xxx”title=”xxx”> 属性可取值如下: 属性名称 属性值 说明 src URL 图片路径 alt 文本 图片无法显示时的文本 ...
- Android笔记:去除标题栏
1: 在oncreate方法中添加requestWindowFeature(Window.FEATURE_NO_TITLE); 必须在setContentView()之前执行. 2: 在Android ...
- *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext iOS9.1闪退问题解决
错误原因在于 AppDelegate 中 didFinishLaunchingWithOptions 结束前 未定义 rootViewController,Xcode7规定必须要有rootViewCo ...
- 数据库支持emoji表情
从MySQL5.5.3开始,MySQL 支持一种utf8mb4的字符集,这个字符集能够支持4字节的UTF8编码的字符.utf8mb4字符集能够完美地兼容utf8字符串.在数据存储方面,当一个普通中文字 ...
- Elasticsearch在Windows下的安装
下载Elasticsearch,地址:elasticsearch.org/download 下载jdk,百度搜索jdk下载即可 配置JAVA_HOME变量,配置方法在此文:http://jingyan ...
- python中最简单的多进程程序
学着.. #!/usr/bin/env python # -*- coding: utf-8 -*- # Spawn a Process: Chapter 3: Process Based Paral ...
- Visual Studio 2015的Web扩展包
过去几年,Visual Studio扩展功能生态系统得到了蓬勃发展,社区贡献出了大量优秀的扩展,其中也包括大量针对Web开发的扩展.但是很多时候,感觉寻找.安装.更新好 几个扩展,总显得比较麻烦.如果 ...
- C# NamePipe使用小结
最近在一次项目中使用到了C#中命名管道,所以在此写下一篇小结备忘. 为什么要使用命名管道呢?为了实现两个程序之间的数据交换.假设下面一个场景.在同一台PC上,程序A与程序B需要进行数据通信,此时我们就 ...
- 如何通过阅读C标准来解决C语言语法问题
有时候必须非常专注地阅读ANSI C标准才能找到某个问题的答案.一位销售工程师把下面这段代码作为测试用例发给Sun的编译小组. foo(const char **p) {} int main(int ...