BAPC 2014 Preliminary

Posted zllwxm123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BAPC 2014 Preliminary相关的知识,希望对你有一定的参考价值。

 

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^91n,k109): 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

注意加特判为一的时候.

 1 #include <iostream>
 2 #define ll long long int
 3 using namespace std;
 4 
 5 ll n;
 6  int main(){
 7      cin>>n;
 8     ll a,b;
 9     while(n--){
10         cin>>a>>b;
11         ll x = 1;
12         bool flag = false;
13         if(a==1){
14             cout<<"0"<<endl;
15             continue;
16         }
17         for(ll i=0;i<=30;i++){
18             x*=b;
19             // cout<<x<<" ";
20             if(x%a==0){
21                 cout<<i+1<<endl;
22                 flag = true;
23                 break;
24             }
25             x=x%a;
26         }
27         if(!flag){
28             cout<<"unbounded"<<endl;
29         }
30     }
31     return 0;
32 }


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 (1leq n leq 100001n10000 and 1 leq d leq 1000001d100000 and 1 leq c leq n1cn): 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 n1a,bn and a != ba !=b and 0 leq s leq 1 0000s1000), 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
用最短路径找出来,然后找到花费最大的,
在统计有多少节点被经历过.


#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define N 10010
#define mem(a) memset(a,0,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef pair<int,int> P;

struct Edge{
    int to,cost;
};
vector<Edge> v[N];
int d[N];
int num[N];
void dijk(int k){
    priority_queue<P, vector<P>, greater<P> > q;
    fill(d,d+N,inf);
    d[k] = 0;
    q.push(P(0,k));

    while(!q.empty()){
        P p = q.top();
        q.pop();
        int x = p.second;
        if(d[x] < p.first)  continue;
        for(int i=0;i<v[x].size();i++){
            Edge e = v[x][i];
            if(d[e.to]>d[x]+e.cost){
                d[e.to] = d[x]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
}
int main(){
    int m;
    cin>>m;
    while(m--){
        mem(d);
        for(int i=0;i<N;i++){
            v[i].clear();
        }
        int n,l,c;
        cin>>n>>l>>c;
        while(l--){
            int a,b,s;
            cin>>a>>b>>s;
            Edge e ;
            e.to = a;
            e.cost = s;
            v[b].push_back(e);
        }
        dijk(c);
        int ans = 0;
        int sum = 0;
        for(int i=1;i<=n;i++){
            // cout<<d[i]<<" ";
            if(d[i]>sum&&d[i]!=inf)
                sum = d[i];

            if(d[i]!=inf){
                ans++;
            }
        }
        cout<<ans<<" "<<sum<<endl;
    }
    return 0;
}

 

 

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 3601h360): 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

大水题
 1 #include <iostream>
 2 #define N 1600
 3 using namespace std;
 4 
 5 int n;
 6 int main(){
 7     cin>>n;
 8     while(n--){
 9         int m;
10         cin>>m;
11         m+=5;
12         m=m%180;
13         m=m/10;
14         if(m==0){
15             cout<<"18"<<endl;
16         }else if(m<10){
17             cout<<"0"<<m<<endl;
18         }else{
19             cout<<m<<endl;
20         }
21     }
22     return 0;
23 }

 





以上是关于BAPC 2014 Preliminary的主要内容,如果未能解决你的问题,请参考以下文章

BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 A. Choosing Ice Cream-gcd B. Failing C

BAPC2014 B&amp;&amp;HUNNU11582:Button Bashing(BFS)

2020.03.14 Preliminaries for BAPC 2019 解题报告

2020年3月14日 BAPC2019 比赛补题报告

2020年3月21日 BAPC 2019 比赛补题报告

The Preliminary Contest for ICPC Asia Yinchuan 2019