(Codeforces Round #413, rated, Div. 1 + Div. 2)(A+B)

来源:互联网 发布:linux 如何进入grub 编辑:程序博客网 时间:2024/05/16 01:20

A. Carrot Cakes
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don’t have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can’t build more than one oven.

Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.

Input
The only line contains four integers n, t, k, d (1 ≤ n, t, k, d ≤ 1 000) — the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven.

Output
If it is reasonable to build the second oven, print “YES”. Otherwise print “NO”.

Examples
input
8 6 4 5
output
YES
input
8 6 4 6
output
NO
input
10 3 11 4
output
NO
input
4 2 1 4
output
YES
Note
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.

In the second example it doesn’t matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.

In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
题意:n个物品,每t分钟可以生产k个,d分钟可以有新一台机器加入(同时)。问新的机器是否可以提高效率。
题解:如果d分钟的时候剩余产品数小于等于k个,就不能提高效率。
代码:

#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e6;int n,t,k,d;int main(){    cin>>n>>t>>k>>d;    int cnt=(n+k-1)/k;    int cnt2=d/t;    if(cnt-cnt2<=1) cout<<"NO"<<endl;    else cout<<"YES"<<endl;}

B. T-shirt buying
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi is back color of the i-th t-shirt. All values pi are distinct, and values ai and bi are integers from 1 to 3.

m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color cj.

A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won’t buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.

You are to compute the prices each buyer will pay for t-shirts.

Input
The first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts.

The following line contains sequence of integers p1, p2, …, pn (1 ≤ pi ≤ 1 000 000 000), where pi equals to the price of the i-th t-shirt.

The following line contains sequence of integers a1, a2, …, an (1 ≤ ai ≤ 3), where ai equals to the front color of the i-th t-shirt.

The following line contains sequence of integers b1, b2, …, bn (1 ≤ bi ≤ 3), where bi equals to the back color of the i-th t-shirt.

The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.

The following line contains sequence c1, c2, …, cm (1 ≤ cj ≤ 3), where cj equals to the favorite color of the j-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.

Output
Print to the first line m integers — the j-th integer should be equal to the price of the t-shirt which the j-th buyer will buy. If the j-th buyer won’t buy anything, print -1.

Examples
input
5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1
output
200 400 300 500 911 -1
input
2
1000000000 1
1 1
1 2
2
2 1
output
1 1000000000
题意:n件衣服,有不同的价格。每个衣服有两种颜色(颜色不超过三种)。对于m个顾客, 他有一个喜欢的颜色。问他能买到价格最低且颜色为他喜欢的。没有输出-1。
题解:因为颜色很少,所以我们开set存一下即可。每次购买后记得删除。
代码:

#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e6;set<int>p[10];int pr[N];int x,m;int main(){    int n;    cin>>n;    for(int i=0;i<n;i++)    {        cin>>pr[i];    }    for(int i=0;i<n;i++)    {        cin>>x;        p[x].insert(pr[i]);    }    for(int i=0;i<n;i++)    {        cin>>x;        p[x].insert(pr[i]);    }    cin>>m;    for(int i=0;i<m;i++)    {        cin>>x;        if(!p[x].empty())        {            x=*p[x].begin();            cout<<x<<" ";            for(int j=0;j<4;j++)            {                p[j].erase(x);            }        }        else            cout<<"-1"<<" ";    }}
0 0
原创粉丝点击