Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
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 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.
题目链接:http://codeforces.com/contest/799/problem/A
分析:计算 不造第二台需要的时间,还有造出第二台 做出一个蛋糕需要的时间 如果小于第一台需要的总时间 则YES
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int n,t,k,d;
6 while(scanf("%d%d%d%d",&n,&t,&k,&d)!=EOF)
7 {
8 int t1;
9 if(n%k==0)
10 t1=n/k*t;
11 else t1=(n/k+1)*t;
12 int t2=d+t;
13 if(t2<t1)
14 printf("YESn");
15 else printf("NOn");
16 }
17 return 0;
18 }
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 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
题目链接:http://codeforces.com/contest/799/problem/B
分析:每人选择一件衣服 价钱最小的而且颜色有一面是自己喜欢的,用优先队列做的,看看就好
下面给出AC代码:
1 #include <bits/stdc++.h>
2 typedef long long ll;
3 using namespace std;
4 int n,m;
5 int flag[200200];
6 class A
7 {
8 public: int id,p;
9 int operator()(A a,A b)
10 {
11 return a.p>b.p;
12 }
13 };
14 priority_queue<A,vector<A>,A> q1,q2,q3;
15 int a[200200],b[200200],c[200200];
16 void init()
17 {
18 cin>>n;
19 for(int i=1;i<=n;i++)
20 scanf("%d",a+i);
21 for(int i=1;i<=n;i++)
22 scanf("%d",b+i);
23 for(int i=1;i<=n;i++)
24 scanf("%d",c+i);
25 }
26 int main()
27 {
28 init();
29 A t;
30 for(int i=1;i<=n;i++)
31 {
32 t.id=i;t.p=a[i];
33 if(b[i]==1 || c[i]==1)
34 q1.push(t);
35 if(b[i]==2 || c[i]==2)
36 q2.push(t);
37 if(b[i]==3 || c[i]==3)
38 q3.push(t);
39 }
40 cin>>m;
41 int k;
42 while(m--)
43 {
44 scanf("%d",&k);
45 int f=0;
46 if(k==1)
47 {
48 while(q1.size())
49 {
50 t=q1.top();q1.pop();
51 if(flag[t.id]==0)
52 {
53 flag[t.id]=1;
54 f=1;
55 break;
56 }
57 }
58 }
59 else if(k==2)
60 {
61 while(q2.size())
62 {
63 t=q2.top();q2.pop();
64 if(flag[t.id]==0)
65 {
66 flag[t.id]=1;f=1;break;
67 }
68 }
69 }
70 else
71 {
72 while(q3.size())
73 {
74 t=q3.top();q3.pop();
75 if(flag[t.id]==0)
76 {
77 flag[t.id]=1;
78 f=1;
79 break;
80 }
81 }
82 }
83 if(f)
84 printf("%d ",t.p);
85 else
86 printf("%d ",-1);
87 }
88 return 0;
89 }
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 n, c and d (2 ≤ n ≤ 100 000, 0 ≤ 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
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
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.
题目链接:http://codeforces.com/contest/799/problem/C
题意:你有两种货币,每种只能买相应的东西,给了n个喷泉,每个喷泉有个漂亮值和价格以及你能用哪种货币买,
问用已拥有的货币你买两个喷泉,最大漂亮值多少
必须要买两个,买不起两个就是0
价格的范围很小,可以开个数组dp【i】记录i货币可以买的最大价值
分析:乱搞一下就可以了
下面给出AC代码:
1 #include<bits/stdc++.h>
2 typedef long long ll;
3 using namespace std;
4 struct node
5 {
6 int p,b;
7 }cc[100050],dd[100050];
8 int dp[2][100050];
9 int cmp(node a,node b)
10 {
11 return a.b<b.b;
12 }
13 int main()
14 {
15 int n,c,d,p,b,i,j;
16 int nc=0,nd=0;
17 char ch;
18 cin>>n>>c>>d;
19 for(i=0;i<n;i++)
20 {
21 scanf("%d %d %c",&p,&b,&ch);//这个地方故意把p和b反过来了。。懒得改了
22 node t;
23 t.b=b;
24 t.p=p;
25 if(ch=='C')
26 {
27 cc[nc++]=t;
28 }
29 else
30 {
31 dd[nd++]=t;
32 }
33 }
34 sort(cc,cc+nc,cmp);
35 sort(dd,dd+nd,cmp);
36 node t;
37 t.b=100005;
38 t.p=0;
39 cc[nc]=dd[nd]=t;
40 int ans=0;
41 for(i=0;i<nc;i++)
42 {
43
44 int last=c-cc[i].b;
45 if(last>0)
46 {
47 if(last>=cc[i].b)
48 {
49 if(dp[0][cc[i].b]!=0)
50 {
51 ans=max(ans,dp[0][cc[i].b]+cc[i].p);
52 }
53 }
54 else
55 {
56 if(dp[0][last]!=0)
57 ans=max(ans,dp[0][last]+cc[i].p);
58 }
59 }
60 for(j=cc[i].b;j<=cc[i+1].b;j++)
61 {
62 dp[0][j]=max(max(dp[0][j],dp[0][j-1]),cc[i].p);
63 }
64 }
65 for(i=0;i<nd;i++)
66 {
67
68 int last=d-dd[i].b;
69 if(last>0)
70 {
71 if(last>=dd[i].b)
72 {
73 if(dp[1][dd[i].b]!=0)
74 ans=max(ans,dp[1][dd[i].b]+dd[i].p);
75 }
76 else
77 {
78 if(dp[1][last]!=0)
79 ans=max(ans,dp[1][last]+dd[i].p);
80 }
81 }
82 for(j=dd[i].b;j<=dd[i+1].b;j++)
83 {
84 dp[1][j]=max(max(dp[1][j],dp[1][j-1]),dd[i].p);
85 }
86 }
87 if(ans==0&&(dp[0][c]==0||dp[1][d]==0))
88 cout<<"0"<<endl;
89 else
90 {
91 if(dp[0][c]!=0&&dp[1][d]!=0)
92 ans=max(ans,dp[0][c]+dp[1][d]);
93 cout<<ans<<endl;
94 }
95 return 0;
96 }
- Shiro中的授权问题
- Spring Cloud中服务的发现与消费
- 使用Spring Cloud搭建高可用服务注册中心
- 从Netflix的Hystrix框架理解服务熔断和服务降级
- 使用Spring Cloud搭建服务注册中心
- 技术分享 | kafka的使用场景以及生态系统
- WebSocket刨根问底(二)
- WebSocket刨根问底(三)之群聊
- SDNLAB群分享(四):利用ODL下发流表创建VxLAN网络
- 一个简单的案例带你入门Dubbo分布式框架
- Ajax上传图片以及上传之前先预览
- Spring Cloud中Hystrix的服务降级与异常处理
- Open vSwitch源码解析之基于VxLAN实现NSH解析功能
- Spring Cloud自定义Hystrix请求命令
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 通过 PHP 原生代码实现 HTTP 控制器
- Go 视图模板篇(一):模板引擎的定义、解析与执行
- Mycat分库分表全解析 Part 6 Mycat 全局序列号
- 通过 PHP 原生代码实现视图模板引擎的解析和渲染
- [MySQL故障处理]记一次innobackupex导致的从库无法同步的问题
- [Oracle 故障处理]记一次DG数据文件无法创建的问题
- mysqldump命令详解 4-按条件备份表数据
- mysqldump命令详解 5-导出事件,函数和存储过程
- [Oracle集群软件全解析]Oracle Cluster Registry Utility 参考
- mysqldump命令详解 Part 8 其他的一些的参数的介绍
- mysqldump命令详解 Part 6- --master-data参数的使用
- 腾讯云语音识别.net-sdk使用笔记0818
- mysqldump命令详解 Part 9 mysqldump命令总结
- [MySQL学习笔记] 3.mysqldump命令详解 Part 2 -备份全库
- [MySQL学习笔记]1. MySQL测试数据的构造