Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)

1.题目链接

http://codeforces.com/contest/799/problem/A

2.题面

A. Carrot Cakes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 ntkd (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
Copy
8 6 4 5
output
Copy
YES
input
Copy
8 6 4 6
output
Copy
NO
input
Copy
10 3 11 4
output
Copy
NO
input
Copy
4 2 1 4
output
Copy
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 6minutes 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.

3.题意

题意就是让你做N个面包,每个烤炉t分钟能做k个面包,你可以花费d时间造第二个烤炉,但是你最多拥有两个烤炉,现在想知道,造第二个烤炉是否有用,注意,在造第二个烤炉的同时,第一个烤炉仍然可以继续烤面包。

4.思路

算出两种方案分别需要的时间,然后

5.代码实现

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2005;
const int Mod=1e9+7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl

int main()
{
    ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,t,k,d;
    cin>>n>>t>>k>>d;
    int sum1=(n/k+(n%k!=0))*t;
    int sum2=0;
    int flag;
    sum2+=d/t*k;
    for(int i=d+1;;i++)
    {
        if(i%t==0)
        {
            sum2+=k;
        }
        if((i-d)%t==0)
        {
            sum2+=k;
        }
        if(sum2>=n)
        {
            flag=i;
            break;
        }
    }
    //dbg(sum1);
    //dbg(flag);
    if(sum1<=flag)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

6.反思

把题读懂样例算好再做题,不然耽误时间。

1.题目链接

http://codeforces.com/contest/799/problem/B

2.题面

B. T-shirt buying
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers piai 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
Copy
5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1
output
Copy
200 400 300 500 911 -1 
input
Copy
2
1000000000 1
1 1
1 2
2
2 1
output
Copy
1 1000000000 

3.题意

题意就是有n个衬衫要卖,每个衬衫前后颜色不同而且每个衬衫有一定的价格,颜色一共有三种,现在有m个人要买衬衫,每个人有一种喜欢的颜色,他们只会买自己喜欢的颜色的衬衫,如果有很多,就买最便宜的,如果没有喜欢的颜色就不买,输出每个人花费的钱,如果没有买,输出-1。

4.思路

首先每个人肯定要买某种颜色最便宜的那个,所以先按照价格排序,然后对于每种颜色建一个set,存一下按价格排序后的下标,然后模拟买衣服的过程,每次取set的首元素,然后删除那个衣服的两种颜色在set中的下标,就结束了。

5.代码实现

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" "<<(x)<<endl;
struct data
{
    int w,f,b;
}a[maxn];
bool cmp(const data &a,const data &b)
{
    return a.w<b.w;
}
set<int> s[4];
int cnt[4];
int book[4][maxn];
void print()
{
    for(int i=1;i<=3;i++)
        cout<<cnt[i]<<" ";
        cout<<endl;
    return ;
}
int main()
{
    ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i].w;
    for(int i=0;i<n;i++) cin>>a[i].f;
    for(int i=0;i<n;i++) cin>>a[i].b;
    sort(a,a+n,cmp);
    cin>>m;
    for(int i=0;i<n;i++)
    {
        s[a[i].f].insert(i);
        s[a[i].b].insert(i);
    }
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        if(s[x].empty())
        {
            cout<<-1<<" ";
            continue;
        }
        int tmp=*s[x].begin();
        cout<<a[tmp].w<<" ";
        s[a[tmp].f].erase(tmp);
        s[a[tmp].b].erase(tmp);
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


6.反思

学会使用set的erase还有取首元素的方式int tmp=*s.begin();

1.题目链接

http://codeforces.com/contest/799/problem/C

2.题面

C. Fountains
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.

Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.

Input

The first line contains three integers nc and d (2 ≤ n ≤ 100 0000 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has.

The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.

Output

Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.

Examples
input
Copy
3 7 6
10 8 C
4 3 C
5 6 D
output
Copy
9
input
Copy
2 4 5
2 5 C
2 1 D
output
Copy
0
input
Copy
3 10 10
5 5 C
5 5 C
10 11 D
output
Copy
10
Note

In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.

In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.

3.题意

就是你有两种不能转换的货币,你要买两个喷泉,每种喷泉只能用固定的货币去买,而且会有固定的价值,现在给你n个喷泉的花费以及价值,问你买两个喷泉能获得的最大价值。

4.思路

一共只有三种购买方式,都用第一种货币购买,都用第二种货币购买,或者第一种买一个第二种买一个。所以可以对于每种花费带来的价值插入到树状数组中,然后区间查询最大值,对两种货币建两棵树,对三种情况取max就ok了。

5.代码实现

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn =1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
int C[maxn+10],D[maxn+10];
void add(int *tree,int k,int num)
{
    while(k<=maxn)
    {
        tree[k] = max(tree[k],num);
        k+=k&-k;
    }
}

int get(int *tree,int k)
{
    int res=0;
    while(k)
    {
        res = max(res,tree[k]);
        k-=k&-k;
    }
    return res;
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,c,d,i,j,maxn;
    cin>>n>>c>>d;
    int ans = 0;
    for(i=1;i<=n;i++)
    {
        int b,p;
        char str[5];
        scanf("%d%d%s",&b,&p,str);
        if(str[0] == 'C')
        {
            maxn = get(D,d);
            if(p > c)  continue;
            maxn = max(maxn,get(C,c-p));
            add(C,p,b);
        }
        else
        {
            maxn = get(C,c);
            if(p > d)  continue;
            maxn = max(maxn,get(D,d-p));
            add(D,p,b);
        }
        if(maxn!=0)
            ans = max(ans,maxn + b);
    }
    cout << ans << endl;
   //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

6.反思

看数据范围设计算法,这个题要想到对每种喷泉只有买或者不买,所以问题是看剩下的钱能买的最大价值,所以可以维护一个到当前的最大值。

1.题目链接

http://codeforces.com/contest/799/problem/D

2.题面

D. Field expansion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by ai. Each extension can't be used more than once, the extensions can be used in any order.

Now Arkady's field has size h × w. He wants to enlarge it so that it is possible to place a rectangle of size a × b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.

Input

The first line contains five integers abhw and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions.

The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multiplies by when the i-th extension is applied.

Output

Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.

Examples
input
Copy
3 3 2 4 4
2 5 4 10
output
Copy
1
input
Copy
3 3 3 3 5
2 3 5 4 2
output
Copy
0
input
Copy
5 5 1 2 3
2 2 3
output
Copy
-1
input
Copy
3 4 1 1 3
2 3 2
output
Copy
3
Note

In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.

3.题意

很简单的题意,给你一个h*w的矩形,每次可以长或宽扩大a[i]倍,问你最少需要几次扩大这个矩形能够放得下a*b的矩形。

4.思路

肯定是要先使用大的倍数,所以先排个序,然后dfs。有两个剪枝,第一个是如果长或宽中的某个已经够了,就不需要再扩大这条变了,另一个是如果当前的倍数已经为2了,那么剩下的肯定都是2,就直接用除法算出需要多个,不需要dfs了。

5.代码实现

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod=1e9+7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back

ll a,b,h,w,n,ans;
ll xx[maxn];
bool cmp(ll a,ll b)
{
    return a>b;
}
void dfs(ll x,ll y,ll m)
{
    if(m==n+1)
        return ;
    if(x>=a&&y>=b)
    {
        ans=min(ans,m);
        return;
    }
    if(xx[m]==2)
    {
        if(x<a)
        {
            while(x<a&&m<n)
            {
                x*=2;
                m++;
            }
        }
        if(y<b)
        {
            while(y<b&&m<n)
            {
                y*=2;
                m++;
            }
        }
         if(x>=a&&y>=b)
        {
            ans=min(ans,m);
        }
        return ;
    }
    if(x<a)
        dfs(x*xx[m],y,m+1);
    if(y<b)
        dfs(x,y*xx[m],m+1);
    return ;
}
int main()
{
    ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    ans=LL_INF;
    cin>>a>>b>>h>>w>>n;
    for(int i=0;i<n;i++)
        cin>>xx[i];
    sort(xx,xx+n,cmp);
    dfs(h,w,0);
    dfs(w,h,0);
    if(ans==LL_INF)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


6.反思

dfs多想剪枝,没准就能卡过去。

常思考排序对一道题有没有用。


猜你喜欢

转载自blog.csdn.net/qq_38891827/article/details/80017309