Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
Problem A
水题,水一水。
#include<bits/stdc++.h>
using namespace std;
int n;
char s[];
int main()
{
cin>>n;
int cnt1=,cnt2=;
scanf("%s",s);
for(int i=;i<n-;i++)
{
if(s[i]=='S' && s[i+]=='F') cnt1++;
else if(s[i]=='F' && s[i+]=='S') cnt2++;
}
if(cnt1>cnt2) puts("YES");
else puts("NO");
return ;
}
Problem B
题目大意:给你数字n,让你给出一个钱的总数m,和钱的种类n个,要求用这些种类的钱
构成m的种数为n。
思路:我是用5和2两种钱构造的,我们考虑构成10 的种数一共只有两种,一种是2 2 2 2 2,另一种是
5 5,那么20 就是三种,30就是四种,40就是五种,一直这样构造下去,忘了考虑一种情况WA了一次。。。
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
scanf("%d",&n);
if(n==)
{
puts("1 1");
puts("");
return ;
}
printf("%d 2\n",(n-)*);
puts("5 2");
return ;
}
Promblem C
题目大意:现在有n个人需要吃si 片披萨,一共有两种披萨A,B,第i个人吃一片A披萨获得的
愉悦值为ai,B为bi,一块披萨能分成S片,我们要买最少的披萨,问你最大愉悦值是多少。
思路:我们先让每个人吃获得愉悦值大的披萨,然后统计A披萨的片数和B披萨的片数,
A和B对S 取膜,剩下的就是不确定的,如果A+B>S则买两种披萨各一个,如果A+B<=S
则买一个披萨,两种披萨都模拟一遍取愉悦值大的。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+;
ll _abs(ll x)
{
if(x>=) return x;
else return -x;
}
struct node
{
ll s,a,b;
bool operator < (const node &rhy)const
{
return _abs(a-b)<_abs(rhy.a-rhy.b);
}
}p[N];
ll n,S;
ll work(ll c1,ll c2)
{
ll ans=;
if(c1)
{
for(int i=;i<n;i++)
{
if(p[i].a<p[i].b) continue;
if(p[i].s>=c1) ans+=c1*(p[i].a-p[i].b);
else ans+=p[i].s*(p[i].a-p[i].b);
c1-=p[i].s;
if(c1<=) break;
}
}
else
{
for(int i=;i<n;i++)
{
if(p[i].a>=p[i].b) continue;
if(p[i].s>=c2) ans+=c2*(p[i].b-p[i].a);
else ans+=p[i].s*(p[i].b-p[i].a);
c2-=p[i].s;
if(c2<=) break;
}
}
return ans;
}
int main()
{
cin>>n>>S;
ll sum=,ans=;
ll res1=,res2=;
for(int i=;i<n;i++)
{
scanf("%I64d%I64d%I64d",&p[i].s,&p[i].a,&p[i].b);
ans+=p[i].s*max(p[i].a,p[i].b);
if(p[i].a>=p[i].b) res1+=p[i].s;
else res2+=p[i].s;
}
res1=res1%S; res2=res2%S;
if(res1+res2>S)
{
printf("%I64d\n",ans);
return ;
}
ll res=1e18;
sort(p,p+n);
res=min(res,work(,res2));
res=min(res,work(res1,));
printf("%I64d\n",ans-res);
return ;
}
Problem E
题目大意:给你一些股票每天的价格,每一天你可以选择买,卖,或者啥都不干,问你
利润最大多少。
思路:智力题,我不会! 用优先队列维护最小值,我们取一个数b,如果这个数比堆顶的
元素a小,则将b加入优先队列,如果b比a大,删除a,加入两个b,(b-a)加入ans,
第一个b相当于把a变成了b,第二个b是自身。
#include<bits/stdc++.h>
using namespace std;
const int N=*1e5+;
int n,a[N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
priority_queue<int,vector<int>,greater<int> > Q;
long long ans=;
for(int i=;i<=n;i++)
{
if(Q.empty())
{
Q.push(a[i]);
continue;
}
int t=Q.top();
if(t>=a[i]) Q.push(a[i]);
else
{
ans+=a[i]-t;
Q.pop();
Q.push(a[i]); Q.push(a[i]);
}
}
printf("%I64d\n",ans);
return ;
}
Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)的更多相关文章
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E
题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同: 题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #500 (Div. 2) [based on EJOI]
Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)
A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...
- Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937
https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...
随机推荐
- spring boot(十):定时任务
springboot默认已经帮我们实行了,只需要添加相应的注解就可以实现. 1.pom包配置 <dependency> <groupId>org.springframework ...
- Java Web之路(五)JSP
一.jsp的3个指令 JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: p ...
- 文本编辑框QTextEdit
QTextEdit类是一个多行文本框控件,可以显示多行文本内容,当文本内容超出控件显示范围时,可以显示水平个垂直滚动条,Qtextedit不仅可以用来显示文本还可以用来显示HTML文档 import ...
- android 使用web查看SQLite数据
添加依赖: compile 'com.facebook.stetho:stetho:1.4.2'compile 'com.facebook.stetho:stetho-okhttp3:1.4.2' 初 ...
- IP分片丢失重传 - Sacrifice的日志 - 网易博客
尽管IP分片看起来是是透明的,但有一点让人不想使用它:即使只丢失一片数据也要重传整个数据报.为什么会发生这种情况呢? 因为IP层本身没有超时重传的机制--由更高层来负责超时和重传(TC ...
- Potential Pythonic Pitfalls
Potential Pythonic Pitfalls Monday, 11 May 2015 Table of Contents Not Knowing the Python Version Obs ...
- R-CNN论文详解(转载)
这几天在看<Rich feature hierarchies for accurate object detection and semantic segmentation >,觉得作者的 ...
- 使用neo4j-import工具导入数据
从Neo4j2.2版本开始,系统就自带了一个大数据量的导入工具:neo4j-import,可支持并行.可扩展的大规模csv数据导入(本例版本为:3.4.7版本) 1.前提条件 关闭neo4j 无法在原 ...
- Asp.Net Core 快速邮件队列设计与实现
发送邮件几乎是软件系统中必不可少的功能,在Asp.Net Core 中我们可以使用MailKit发送邮件,MailKit发送邮件比较简单,网上有许多可以参考的文章,但是应该注意附件名长度,和附件名不能 ...
- Cookie/Session机制详解(转载)
原文链接:http://blog.csdn.net/fangaoxin/article/details/6952954 会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用 ...