Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
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.
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.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
8 6 4 5
YES
8 6 4 6
NO
10 3 11 4
NO
4 2 1 4
YES
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代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t,k,d;
while(scanf("%d%d%d%d",&n,&t,&k,&d)!=EOF)
{
int t1;
if(n%k==)
t1=n/k*t;
else t1=(n/k+)*t;
int t2=d+t;
if(t2<t1)
printf("YES\n");
else printf("NO\n");
}
return ;
}
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 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.
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.
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.
5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1
200 400 300 500 911 -1
2
1000000000 1
1 1
1 2
2
2 1
1 1000000000
题目链接:http://codeforces.com/contest/799/problem/B
分析:每人选择一件衣服 价钱最小的而且颜色有一面是自己喜欢的,用优先队列做的,看看就好
下面给出AC代码:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,m;
int flag[];
class A
{
public: int id,p;
int operator()(A a,A b)
{
return a.p>b.p;
}
};
priority_queue<A,vector<A>,A> q1,q2,q3;
int a[],b[],c[];
void init()
{
cin>>n;
for(int i=;i<=n;i++)
scanf("%d",a+i);
for(int i=;i<=n;i++)
scanf("%d",b+i);
for(int i=;i<=n;i++)
scanf("%d",c+i);
}
int main()
{
init();
A t;
for(int i=;i<=n;i++)
{
t.id=i;t.p=a[i];
if(b[i]== || c[i]==)
q1.push(t);
if(b[i]== || c[i]==)
q2.push(t);
if(b[i]== || c[i]==)
q3.push(t);
}
cin>>m;
int k;
while(m--)
{
scanf("%d",&k);
int f=;
if(k==)
{
while(q1.size())
{
t=q1.top();q1.pop();
if(flag[t.id]==)
{
flag[t.id]=;
f=;
break;
}
}
}
else if(k==)
{
while(q2.size())
{
t=q2.top();q2.pop();
if(flag[t.id]==)
{
flag[t.id]=;f=;break;
}
}
}
else
{
while(q3.size())
{
t=q3.top();q3.pop();
if(flag[t.id]==)
{
flag[t.id]=;
f=;
break;
}
}
}
if(f)
printf("%d ",t.p);
else
printf("%d ",-);
}
return ;
}
C. Fountains
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.
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.
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
3 7 6
10 8 C
4 3 C
5 6 D
9
2 4 5
2 5 C
2 1 D
0
3 10 10
5 5 C
5 5 C
10 11 D
10
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代码:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct node
{
int p,b;
}cc[],dd[];
int dp[][];
int cmp(node a,node b)
{
return a.b<b.b;
}
int main()
{
int n,c,d,p,b,i,j;
int nc=,nd=;
char ch;
cin>>n>>c>>d;
for(i=;i<n;i++)
{
scanf("%d %d %c",&p,&b,&ch);//这个地方故意把p和b反过来了。。懒得改了
node t;
t.b=b;
t.p=p;
if(ch=='C')
{
cc[nc++]=t;
}
else
{
dd[nd++]=t;
}
}
sort(cc,cc+nc,cmp);
sort(dd,dd+nd,cmp);
node t;
t.b=;
t.p=;
cc[nc]=dd[nd]=t;
int ans=;
for(i=;i<nc;i++)
{ int last=c-cc[i].b;
if(last>)
{
if(last>=cc[i].b)
{
if(dp[][cc[i].b]!=)
{
ans=max(ans,dp[][cc[i].b]+cc[i].p);
}
}
else
{
if(dp[][last]!=)
ans=max(ans,dp[][last]+cc[i].p);
}
}
for(j=cc[i].b;j<=cc[i+].b;j++)
{
dp[][j]=max(max(dp[][j],dp[][j-]),cc[i].p);
}
}
for(i=;i<nd;i++)
{ int last=d-dd[i].b;
if(last>)
{
if(last>=dd[i].b)
{
if(dp[][dd[i].b]!=)
ans=max(ans,dp[][dd[i].b]+dd[i].p);
}
else
{
if(dp[][last]!=)
ans=max(ans,dp[][last]+dd[i].p);
}
}
for(j=dd[i].b;j<=dd[i+].b;j++)
{
dp[][j]=max(max(dp[][j],dp[][j-]),dd[i].p);
}
}
if(ans==&&(dp[][c]==||dp[][d]==))
cout<<""<<endl;
else
{
if(dp[][c]!=&&dp[][d]!=)
ans=max(ans,dp[][c]+dp[][d]);
cout<<ans<<endl;
}
return ;
}
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)的更多相关文章
- C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)
题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生
我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
- 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...
- 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...
- 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)
http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 ...
随机推荐
- Python云端系统开发入门——框架基础
Django框架基础 这是我学习北京理工大学嵩天老师的<Python云端系统开发入门>课程的笔记,在此我特别感谢老师的精彩讲解和对我的引导. 1.Django简介与安装 Django是一个 ...
- HTML干货
什么也不想说 <%@ page language="java" import="java.util.*" pageEncoding="utf-8 ...
- [array] leetcode - 33. Search in Rotated Sorted Array - Medium
leetcode - 33. Search in Rotated Sorted Array - Medium descrition Suppose an array sorted in ascendi ...
- BGP网络学习总结
1.前言 云计算在中国发展越来越快,企业逐步开始将业务迁移到公有云中,方便运维,节省成本.公有云最复杂的地方是网络,客户对网络的需求千奇百怪,造成网络环境极其复杂,稍有不慎,就会出现网络连通性 ...
- jsDOM编程-乌龟抓小鸡游戏
<html> <head> <title>js乌龟抓小鸡游戏 </title> <meta http-equiv="conten ...
- python 中一些关键字的区别
一.raw_input 和input input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 1.当输入为纯数字时 input返回的是数值类型, ...
- 数组a[n]中存放1-n中的n-1个数,给出算法找出重复的那一个数
问题描述: 数组a[n]中存放1-n中的n-1个数,给出算法找出重复的那一个数. 算法一: 对数组a[n]进行冒泡排序,如果冒泡所得的最值和前一个最值相等,则该最值为重复的数. 分析: 该算法时间复杂 ...
- Node.js 蚕食计划(三)—— Express 启航
如果看过上一篇<Node.js 蚕食计划>,就会发现手动搭建一个 web 服务器还是比较繁琐 而 express 就是一个可以极大地提高开发效率的 web 开发框架 一.创建项目 在 ex ...
- 微信小程序开发之常见BUG
1.wx:if 当前版本为1.3.0,正常使用 <view wx:if="{{length > 5}}"> 1 </view> <view wx ...
- SVG 入门——理解viewport,viewbox,preserveAspectRatio
工欲善其事必先利其器,没有真正搞懂SVG里的viewport,viewbox, preserveAspectRatio这三个属性,就很容易遇到坑,最近写项目用到svg这三个属性被我一眼就略过 ,后来发 ...