题目连接

排行榜

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的更多相关文章

  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. October 13th 2016 Week 42nd Thursday

    If the world seems cold to you, kindle fires to warm it. 若世界以寒相待,请点燃火堆以温暖相报. Kindle fires to warm th ...

  2. 模拟赛1029d1

    第二题[题目描述]给你两个日期,问这两个日期差了多少毫秒.[输入格式]两行,每行一个日期,日期格式保证为"YYYY-MM-DD hh:mm:ss"这种形式.第二个日期时间一定比第一 ...

  3. UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃

      UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃 [摘要:reason: '-[UITableView _conten ...

  4. PHP面向对象——重写与重载

    重写/覆盖           override 指:子类重写了父类的同名方法 class Human{    public function say($name){           echo $ ...

  5. logstash之multiline插件,匹配多行日志

    在外理日志时,除了访问日志外,还要处理运行时日志,该日志大都用程序写的,比如log4j.运行时日志跟访问日志最大的不同是,运行时日志是多行,也就是说,连续的多行才能表达一个意思. 在filter中,加 ...

  6. c++11中的static

    超赞的线程安全的初始化 static plsa::PLSAModel& model() { static plsa::PLSAModel _model = ([&]() { plsa: ...

  7. SQL的一切常用函数展示

    练习了一下, 用时再慢慢看吧. SHOW WARNINGS; SELECT quote(text_fld) FROM string_tbl; ), 'n'); SELECT ASCII('ö'); S ...

  8. djcelery的细节篇

    http://blog.csdn.net/samed/article/details/50598371 随时撸一撸,要点记心间.. 1. 下面讲解一下celery.py文件的配置内容,为何要这么配置. ...

  9. 攻城狮在路上(叁)Linux(十九)--- 磁盘分区

    磁盘分区使用fdisk命令,该命令仅root有使用权限. 磁盘分区的一般步骤: 1.首先用df命令查看设备名 df -h; 2.fdisk /dev/sda; <== 按m显示help d:删除 ...

  10. php获取文件夹下面的文件列表和文件夹列表

    function getDir($dir) { $dirArray[] = NULL; if (false != ($handle = opendir( $dir ))) { $i=0; while ...