ACM-ICPC Asia Training League 暑假第一阶段第一场 ABF

A Choosing Ice Cream

You are standing in the supermarket in front of the freezers. You have a very tough task ahead of you: you have to choose what type of ice cream you want for after dinner that evening. After a while, you give up: they are all awesome! Instead, you take your (fair) kk-sided die out of your pocket and you decide to let fate decide.

Of course, the number of ice cream choices, nn, may not be precisely kk, in which case you could not just throw the die once, rolling ii, and take the iith ice cream choice. You therefore have to use some algorithm that involves zero or more die throws that results in an ice cream choice with every choice being exactly equally likely. Being a good computer scientist, you know about the accept-reject method, which would let you make such a fair choice.

At that point, you remember that you have a very importantcompetition to attend that same afternoon. You absolutely cannot afford to be late for that competition. Because of this, you decide you cannot use the accept-reject method, as there may be no bound on the number of die throws needed to ensure a fair result, so you may end up standing there for a long time and miss the competition! Instead, you resolve to find an algorithm that is fair and uses as few dice choices as possible in the worst case.

Given nn and kk, can you determine the minimum number ii such that there is a fair algorithm that uses at most iidie throws per execution?

Input Format

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with two space-separated integers nn and kk (1 \leq n, k \leq 10^91≤n,k≤109): the number of ice cream choices and the number of sides of your die, respectively.

Output Format

Per test case:

  • one line with a single integer: the smallest number of throws after which you are guaranteed to be able to make a fair choice. If there is no such number, print “unbounded” instead.

样例输入

3
4 2
2 4
3 2

样例输出

2
1
unbounded

题目来源

BAPC 2014 Preliminary

求k^x%n==0中最小的x

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 110;
 5 ll n, t, k;
 6 ll fun(ll i) {
 7     ll ans = 1%n;
 8     while(i--) {
 9         ans *= k;
10         ans %= n;
11     }
12     return ans;
13 }
14 int main() {
15     scanf("%lld",&t);
16     while(t--) {
17         scanf("%lld%lld",&n,&k);
18         bool flag = false;
19         ll i = 0;
20         for(ll j = 1; j <= n; j*=2) {
21             if(fun(i) == 0) {
22                 printf("%lld\n",i);
23                 flag = true;
24                 break;
25             }
26             i++;
27         }
28         if(!flag) printf("unbounded\n");
29     }
30     return 0;
31 }

B Failing Components

As a jury member of the Best Architectural Planning Contest, you are tasked with scoring the reliability of a system. All systems entered in the contest consist of a number of components which depend on each other. The reliability of such a system depends on the damage done by a failing component. Ideally a failing component should have no consequences, but since most components depend on each other, some other components will usually fail as well.

Most components are somewhat resilient to short failures of the components they depend on. For example, a database could be unavailable for a minute before the caches expire and new data must be retrieved from the database. In this case, the caches can survive for a minute after a database failure, before failing themselves. If a component depends on multiple other components which fail, it will fail as soon as it can no longer survive the failure of at least one of the components it depends on. Furthermore no component depends on itself directly, however indirect self-dependency through other components is possible.

You want to know how many components will fail when a certain component fails, and how much time passes before all components that will eventually fail, actually fail. This is difficult to calculate by hand, so you decided to write a program to help you. Given the description of the system, and the initial component that fails, the program should report how many components will fail in total, and how much time passes before all those components have actually failed.

Input Format

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with three space-separated integers nn, dd and cc (1\leq n \leq 100001≤n≤10000 and 1 \leq d \leq 1000001≤d≤100000 and 1 \leq c \leq n1≤c≤n): the total number of components in the system, the number of dependencies between components, and the initial component that fails, respectively.
  • dd lines with three space-separated integers aa, bb and ss (1 \leq a,b \leq n1≤a,b≤n and a\ != ba !=b and 0 \leq s \leq 1 0000≤s≤1000), indicating that component aa depends on component bb, and can survive for ss seconds when component bbfails.

In each test case, all dependencies (a, b)(a,b) are unique.

Output Format

Per test case:

  • one line with two space-separated integers: the total number of components that will fail, and the number of seconds before all components that will fail, have actually failed.

样例输入

2
3 2 2
2 1 5
3 2 5
3 3 1
2 1 2
3 1 8
3 2 4

样例输出

2 5
3 6

题目来源

BAPC 2014 Preliminary

n个组件,d个依赖关系,初试坏的组件为c。依赖关系为a依赖b,在b坏了后a还能运行s秒。求在c坏了后,最后有多少个组件损坏,用的时间是多少秒。

可以转换成最短路径来做。

 1 #include <bits/stdc++.h>
 2 #define INF 0x3f3f3f3f
 3 #define ll long long
 4 using namespace std;
 5 const int N = 10010;
 6 typedef pair<int, int> P;
 7 struct Nod{
 8     int to, w;
 9 };
10 vector<Nod> vs[N];
11 int dist[N];
12
13 void bfs(int s) {
14     priority_queue<P,vector<P>,greater<P> > que;
15     dist[s] = 0;
16     que.push(P(0, s));
17     while(!que.empty()) {
18         P p = que.top(); que.pop();
19         int v = p.second;
20         if(dist[v] < p.first) continue;
21         for(int i = 0; i < vs[v].size(); i ++) {
22             Nod e = vs[v][i];
23             if(dist[e.to] > dist[v] + e.w) {
24                 dist[e.to] = dist[v] + e.w;
25                 que.push(P(dist[e.to], e.to));
26             }
27         }
28     }
29 }
30 int main() {
31     int t, n, d, c;
32     scanf("%d", &t);
33     while(t--) {
34         memset(dist, INF, sizeof(dist));
35         scanf("%d%d%d", &n, &d, &c);
36         for(int i = 0; i < d; i ++) {
37             int a, b, s;
38             Nod e;
39             scanf("%d%d%d", &a, &b, &s);
40             e.to = a, e.w = s;
41             vs[b].push_back(e);
42         }
43         bfs(c);
44         int cnt = 0, MIN = 0;
45         for(int i = 1; i <= n; i ++) {
46             if(dist[i] != INF) {
47                 cnt++;
48                 MIN = max(MIN, dist[i]);
49             }
50         }
51         for(int i = 1; i <= n; i ++) {
52             vs[i].clear();
53         }
54         printf("%d %d\n",cnt,MIN);
55     }
56     return 0;
57 }

F Runway Planning

Most airports have multiple runways. To identify runways, they are given a number indicat- ing the direction of the runway. Such a runway number is obtained by dividing the heading of the runway in degrees by ten, rounding the result, and optionally prefixing it with a ‘0’ if the result has only a single digit. For example, a runway with a heading of 82° is indicated by the number 08.If you are paying attention, you might think “a runway can be used in both directions, and therefore has two headings, but it is only assigned one runway number.” You are correct: normally a runway is identified by two numbers, based on the direction in which the runway is used. To simplify matters, we only concern ourselves with the smallest of these two num- bers, except if it is zero; we then use 18 instead. The runway numbers thus range from 01 to 18.

Now, you might think, “what if two runways have the same heading?” In that case, the characters ‘L’ and ‘R’ are appended to the number of the left and right runway, respectively. But what if three runways have the same heading? Then, the character ‘C’ is appended to the center runway. “But”, I can hear you ask, “what if four runways have the same heading?” If you really want to know, look up how Dallas/Fort Worth International Airport solved this problem after the contest. At any rate, we do not concern ourselves with multiple runways having the same heading in this problem, so you can forget all you read in this paragraph.

The runway in use is mostly determined by the current direction of the wind. It is pre- ferred to take off and land with headwind. If it is not possible to have the wind coming from straight ahead, its direction should be as close to that as possible. For example, if an airport has the runways 05 and 15, and the wind has a heading of 70°, taking off and landing using runway 05 is preferred, since the heading of that runway is closest to the heading of the wind.

Now, consider an airport already having one or more runways, and planning the con- struction of a new runway. Obviously, this runway should have a unique runway number: not only would we otherwise have a problem outside the boundaries of our restricted runway numbering outlined above, but, most importantly, this increases the probability of being able to take off or land with headwind.

The engineers at the airport under consideration have already determined the heading of the new runway, but still need you to determine the runway number. Note that the engineers are not very considerate with their input to your problem. They give you one heading of the runway, but it can be either the lowest or the highest heading of the runway. Be sure to give the lowest of the two runway numbers, as discussed in the second paragraph of this problem statement, even if you are given the highest of the two headings from the engineers.

输入格式

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with a single integer hh (1 \leq h \leq 3601≤h≤360): the heading of the new runway in degrees.

输出格式

Per test case:

  • one line with the runway number of the newly constructed runway.

样例输入

4
82
115
316
4

样例输出

08
12
14
18

题目来源

BAPC 2014 Preliminary

签到题。

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 110;
 5
 6 int main() {
 7     int t, n;
 8     cin >> t;
 9     while(t--) {
10         cin >> n;
11         if(n > 180) n -= 180;
12         n = int(1.0*n/10+0.5);
13         if(n == 0) n = 18;
14         printf("%02d\n",n);
15     }
16     return 0;
17 }

原文地址:https://www.cnblogs.com/xingkongyihao/p/9279813.html

时间: 2024-10-10 02:46:15

ACM-ICPC Asia Training League 暑假第一阶段第一场 ABF的相关文章

Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E. Excellent Engineers-单点更新、区间最值-线段树 G. Growling Gears I. Interesting Integers-类似斐波那契数列-递推思维题

先写这几道题,比赛的时候有事就只签了个到. E. Excellent Engineers 传送门: 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到名单中. 因为是3个变量,所以按其中一个变量进行sort排序,然后,剩下的两个变量,一个当位置pos,一个当值val,通过线段树的单点更新和区间最值操作,就可以把名单确定. 代码: 1 //E-线段树 2 #include<iostream> 3 #include<cstdio> 4 #incl

BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 A. Choosing Ice Cream-gcd B. Failing Components-最短路Dijkstra F. Runway Planning

开始水一波博客 题目链接: A. Choosing Ice Cream 传送门 题意就是n个冰淇淋,骰子有k个面,问你是否能在公平的概率下转几次骰子能确定买哪个冰淇淋. 举个例子,假设我只有一个冰淇淋,我不用转骰子直接就会买这个,所以转骰子的次数是0,如果我有4个冰淇淋,2个骰子面,我可以先把冰淇淋abcd分成两部分,ab一组,cd一组,这是等概率的,我先转一次骰子确定是选ab组还是cd组,然后再转一次就可以确定买哪个了.如果我有6个冰淇淋,12个面,我可以每一种冰淇淋贴2个面,转一次就可以确定

2014 ACM/ICPC Asia Regional Xi&#39;an Online

03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为sqrt(n),问题是怎么快速找到从i开始往前2种颜色.三种.四种...o[]种的位置. 离散化之后,可以边走边记录某个数最后一个出现的位置,初始为-1,而所要求的位置就等于 if(last[a[i]]==-1) 该数没有出现过,num[i][1] = i,num[i][j+1] = num[i-1

2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 802    Accepted Submission(s): 269 Problem Description hannnnah_j is a teacher in WL High school who teaches biolog

【题解】 2015 ACM/ICPC Asia Regional Shenyang Online

[1006] FangFang (暴力枚举) Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 871    Accepted Submission(s): 364 Problem Description Fang Fang says she wants to be remembered. I promise her.

HDU 5785 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)

Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 976    Accepted Submission(s): 375 Problem Description The shorter, the simpler. With this problem, you should be convinced of this tru

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri