Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 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 tminutes 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
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.

 这个A题我一直都不懂啊,就在那里猜意思,懂了又找不到怎么处理那四个数字,按理说样例都给的挺清楚的,但是自己就是一直wa,迷了一会才想到正确地打开方式。

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,t,k,d;
    cin>>n>>t>>k>>d;
    int t1=n/k;
    if(n%k==0)
    t1-=1;
    t1=t1*t;
    if(t1>d&&k<n)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;

    return 0;
}
View Code
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
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 
B题可以算数据结构的,意思就是一群人排队买衣服,买他喜欢的颜色的衣服,如果有多件符合,就买最便宜的,各种姿势各种T,我是感觉自己没有利用这个颜色数比较小的
条件,在随便搞,最后想想还是大神的队列比较好,本来我是觉得我可以重复处理起来比较麻烦,但是确实没有那么麻烦啊
#include <bits/stdc++.h>
using namespace std;
#define MN 200000
struct shirt{int p,a,b;}p[MN+5];
bool cmp(shirt a,shirt b){return a.p<b.p;}
int u[MN+5];
queue<int> v[4];
int main()
{   std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n,i;
    cin>>n;
    for(i=1;i<=n;++i)cin>>p[i].p;
    for(i=1;i<=n;++i)cin>>p[i].a;
    for(i=1;i<=n;++i)cin>>p[i].b;
    sort(p+1,p+n+1,cmp);
    for(i=1;i<=n;++i)
    v[p[i].a].push(i),v[p[i].b].push(i);
    cin>>i;
    for(;i;i--)
    {
        cin>>n;
        while(v[n].size()&&u[v[n].front()])v[n].pop();
        if(v[n].size())cout<<p[v[n].front()].p<<"
",u[v[n].front()]=1;
        else cout<<"-1
";
    }
}
View Code
tourist 的代码,思路更加清晰
#include <bits/stdc++.h>

using namespace std;

const int N = 1234567;

set < pair <int, int> > s[7];
int p[N], a[N], b[N];
bool alive[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", b + i);
  }
  for (int i = 0; i < n; i++) {
    s[a[i]].insert(make_pair(p[i], i));
    s[b[i]].insert(make_pair(p[i], i));
    alive[i] = true;
  }
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int c;
    scanf("%d", &c);
    int ans = -1;
    while (!s[c].empty()) {
      int x = (*(s[c].begin())).second;
      s[c].erase(s[c].begin());
      if (!alive[x]) {
        continue;
      }
      alive[x] = false;
      ans = p[x];
      break;
    }
    printf("%d ", ans);
  }
  puts("");
  return 0;
}
原文地址:https://www.cnblogs.com/BobHuang/p/6843688.html