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 ...
随机推荐
- SQL如何本地数据库连接服务器的数据库
当我们本地数据库的数据作为测试的时候,需要服务器上的数据,但是每次都远程服务器打开数据库查看数据是很麻烦的,那么我们如何让本地的数据库连接服务器上的数据库.前提是你本地的数据库的版本必须和服务器上的数 ...
- 火狐----此地址使用了一个通常用于网络浏览以外的端口。出于安全原因,Firefox 取消了该请求。
FirFox打开80以外的端口,会弹出以下提示: “此地址使用了一个通常用于网络浏览以外的端口.出于安全原因,Firefox 取消了该请求.”.经网上搜索,解决方法如下: 在Firefox地址栏输入a ...
- 方法重载的小demo
方法的重载(overload)要求:1,同一个类中2,方法名必须相同3,方法的参数列表不同(1,参数的个数不同2,参数类型不同,但是参数名相同) 注:方法的重载与方法的返回值类型没有关系 packag ...
- 关于内存管理/set/get方法
MRC状态下 1 任何继承NSObject的对象,存放于堆控件中,都需要手动管理内存 .2 基本数据类型放到栈中,对象放到堆空间中,内存是有系统管理的.(int\float\enum\struct) ...
- NSOperation使用
1.继承NSOperation DownLoadImageTask.h #import <Foundation/Foundation.h> #import <UIKit/UIKit. ...
- valgrind检查C++内存泄漏
valgrind --tool=memcheck --leak-check=full ./httptest Valgrind 使用 用法: valgrind [options] prog-and-ar ...
- python基础语法(二)
本文主要包括以下内容 函数 切片 迭代 列表生成式 生成器 迭代器 函数 定义函数 定义函数 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块 ...
- CLR via C#(05)- 访问限定、数据成员
今天跟大家分享一下关于访问限定和数据成员的知识.主要包括以下两点: Abstract, sealed, virtual, new, override怎么用? Const 和 readonly好像都表示 ...
- JS中级 - 02:表单、表格
getElementsByTagName() getElementsByTagName() 方法可返回带有指定标签名的对象的集合. getElementsByClassName() 返回文档中所有指定 ...
- C# 读取CSV文件
CSV文件是用逗号作为分隔符的,所以如果是简单的CSV文件,用split(',')就可以了. 但是Excel 编辑CSV文件,且内容中有逗号,得到的csv文件如下:"aaa,aaa" ...