地址http://codeforces.com/contest/799

                                  A. Carrot Cakes

    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.   

    现在有n个胡萝卜,一个炉子,一个炉子可以同时做k个胡萝卜,做好需要t分钟,现在允许用d分钟再造一个相同的炉子,两个炉子可以同时工作,判断再建一个炉子是否可以缩短总时间。只能造一个新炉子。

   开始脑子有点混,没看明白,其实根据样例一,旧炉子做胡萝卜蛋糕时,是不能做新炉子的。首先要求出来只用旧的炉子完成任务需要的时间。这里有个细节:如果n%k!=0,那么所需炉子数all=n/k+1。所以此时的alltime=all*t;如果d+t<alltime,是需要建一个新炉子来缩短时间的。因为d时间先做k个,再造一个炉子,这中间第一个炉子还在工作,新炉子造完了就投入使用。能赶在alltime之前造出新炉子,那么就一定可以造出更多胡罗卜蛋糕。

  代码:

  

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int n ,t , k ,d ;
scanf("%d%d%d%d",&n,&t,&k,&d); if(k>=n)
cout<<"NO"<<endl;
else
{
int alltime ;
if(n%k==)
alltime = n/k;
else
alltime= n/k+;
alltime*=t;
if((t+d)<alltime)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
} }

    

    B. T-shirt buying

    

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 

   题意是很好理解的:有n件T恤,每件T体恤都分别有价格(价格各不相同,这点很重要!等一下会说明),前面的颜色(1,2,3)、背部的颜色三种属性。接下来有m个人每个人都有一种喜欢的颜色,他们按先后顺序选择衣服,
如果没有喜欢的颜色的衣服了就输出“-1”,否则选择其中符合条件的衣服中价值最小的。输出每个人要付出的钱。
  看数据,直接暴力的话会T的。我们知道各体恤价格不同,所以可以set[]来做,set里的元素自动排序,而且无重复。比如set[1]=100,200,表示1颜色的价格有100,200两件。某件衣服被买走以后,就把所有
价格等此的数据删除,其实因为价格各不相同,所以我们删除的只是同一件衣服正反面颜色对应的价格而已,就当于这件衣服删除了。比如set[1]=100,set[2]=100,此处的1,2分别表示同一件衣服的正反面,删除两个100,这件衣服就相当于没了。
  具体看代码,注意怎么得到set[].begin(),第一次学到。
  
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 2e5+;
struct node
{
ll p,a,b;
}st[maxn];
int main()
{
int n ;
set<ll>ss[];
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lld",&st[i].p);
for(int i = ; i <= n; i++)
scanf("%lld",&st[i].a);
for(int i = ; i <= n ; i ++)
scanf("%lld",&st[i].b);
for(int i = ; i <= n ; i++)
{
ss[st[i].a].insert(st[i].p);  //set用法注意
ss[st[i].b].insert(st[i].p);
}
int m;
scanf("%d",&m);
for(int i = ; i <= m ; i ++)
{
int x ;
scanf("%d",&x);
if(ss[x].size()==)      //set用法注意
cout<<"-1 ";
else
{
ll mid = *(ss[x].begin());  //set用法注意
cout<<mid<<" ";    //此时的.begin()为当前颜色里价格最便宜的衣服
for(int i= ;i<=;i++)
{
ss[i].erase(mid);
}
}
}
}
  

寒假第一发(CF水题两个)的更多相关文章

  1. 做了一道cf水题

    被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...

  2. 一道cf水题再加两道紫薯题的感悟

    . 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...

  3. 水题两篇 Dream & Find Integer (HDU 6440/6441)

    // 出自ICPC 2018网络赛C - Dream & D - Find Integer // 对大佬来讲的水题,本菜鸡尽量学会的防爆零题... // 今晚翻看vjudge昨日任务上的C题, ...

  4. 某5道CF水题

    1.PolandBall and Hypothesis 题面在这里! 大意就是让你找一个m使得n*m+1是一个合数. 首先对于1和2可以特判,是1输出3,是2输出4. 然后对于其他所有的n,我们都可以 ...

  5. 一道cf水题

    题意:输入数字n表示字符串中元素个数,字符串中只含有RGB三个字符,现在要求任意两个相同的字符他们的下标之差能整除3. 思路:任意两个相同的字符的下标能整除3,也就是任意三个为一组的字符串当中的字符不 ...

  6. 几道cf水题

    题意:给你包含n个元素的数组和k种元素,要求k种元素要用完,并且每种颜色至少用一次,n个元素,如果某几个元素的值相同,这些个元素也不能染成同一种元素. 思路:如果元素个数n小于k或者值相同的元素的个数 ...

  7. cf水题

    题意:输入多组数据,有的数据代表硬币的长宽,有的数据代表钱包的长宽,问你当这组数据代表钱包的长宽时,能不能把它前面出现的所有硬币全部装下. 思路:只要钱包的长宽大于前面出现的所有硬币的长宽就可以装下, ...

  8. 在$CF$水题の记录

    CF1158C CF1163E update after CF1173 很好,我!expert!掉rating了!! 成为pupil指日可待== 下次要记得合理安排时间== ps.一道题都没写的\(a ...

  9. Cf水题B - Combination

    地址: https://vjudge.net/problem/27861/origin Ilya plays a card game by the following rules. A player ...

随机推荐

  1. 今日份学习: springboot 用到的注解

    笔记 上回用到的所有注解 @Around @Aspect @Autowired @Bean @Configuration @RequestMapping @ResponseBody @RestCont ...

  2. Android 自定义PopWindow完整代码

    1.布局文件的编写 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:and ...

  3. 对于java多态的总结

    父类引用指向子类对象是Java比较基础的概念.Java作为一门面向对象编程的语言,调用对象是在编程中经常用到的.尚学堂李老师为大家详细说明这一概念. 例如父类Animal,子类Cat,Dog.其中An ...

  4. Maven:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    还是记录使用 maven 时遇到的问题. 一.maven报错 maven package 进行打包时出现了以下报错: Non-resolvable parent POM for com.wpbxin: ...

  5. 「NOIP2016」愤怒的小鸟

    传送门 Luogu 解题思路 首先这个数据范围十分之小啊. 我们考虑预处理出所有可以带来贡献的抛物线 三点确定一条抛物线都会噻 然后把每条抛物线可以覆盖的点状压起来,然后状压DP随便转移就好了. 有一 ...

  6. (转)spring mvc 中文乱码问题解决

    在eclipse环境里,页面传输数据的时候通常用ISO-8859-1这个字符集可以用 str = new String(str.getBytes("ISO-8859-1"), &q ...

  7. 51nod 1378:夹克老爷的愤怒 很好玩的一道树状dp

    1378 夹克老爷的愤怒 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 夹克老爷逢三抽一之后,由于采用了新师爷的策略,乡民们叫苦不堪,开始组织 ...

  8. java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver java.sql.SQLException

    今天下午一直想用netbeans连接数据库,结果就是来来回回碰到这两个问题. 我还在想,连接数据库并不是一个什么困难的事情啊,我都按照教程上一步一步做的,代码什么的都感觉很好,怎么就找不到类呢,怎么就 ...

  9. phpstudy后门漏洞复现php5.2

    前段时间phpstudy被人发现某些版本存在后门,许多人就这样被当作肉鸡长达两年之久 后门隐藏在程序自带的php的php_xmlrpc.dll模块 影响的版本:phpstudy2016和2018 在H ...

  10. Java生鲜电商平台-优惠券系统设计详解

    Java生鲜电商平台-优惠券系统设计详解 优惠券作为电商最常用的营销手段,对于商家而言可以起到拉新.促活.提高转化的作用,对用户而言也可以获得实惠,今天就来谈谈优惠券系统的设计逻辑. 我对于优惠券系统 ...