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. 题解:很显然只有 \( ...
随机推荐
- jquery 兼容的滚轮事件
// jquery 兼容的滚轮事件 $(document).on("mousewheel DOMMouseScroll", function (e) { ? : -)) || // ...
- tarjan,树剖,倍增求lca
1.tarjan求lca 思想: void tarjan(int u,int f){ for(int i=---){//枚举边 if(v==f) continue; dfs(v); //继续搜 uni ...
- 实现一个string类
实现要实现:构造,析构,拷贝构造,赋值的功能 1. 提供构造函数 string(), string(const string & str),string(const char * str), ...
- CentOS6.8配置SonarQube Scanner配合SonarQube使用
下载最新的SonarQube Scanner压缩包 https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner ...
- cdn.dns,cms
CDN CDN的全称是Content Delivery Network,即内容分发网络.其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快.更稳定.通过在网络各 ...
- Remaiten-一个以路由器和IoT设备为目标的Linux bot
Remaiten-一个以路由器和IoT设备为目标的Linux bot ESET的研究人员正在积极地检测以嵌入式系统为攻击目标的木马,受影响的有路由器,网关和无线访问点.近期,我们已经发现了一个相关的b ...
- Django中全局Context处理器
1.模板标签和模板变量 模板标签在{% %}中定义: {% if is_logged_in %} Thanks for logging in! {% else %} Please log in. {% ...
- python将图片转换为Framebuffer裸数据格式(终端显示图片)【转】
转自:https://www.cnblogs.com/zqb-all/p/6107905.html 要在ubuntu终端显示图片或者在板子的LCD显示图片,Framebuffer是一个简单易用的接口, ...
- dubbo系列七、dubbo @Activate 注解使用和实现解析
一.用法 Activate注解表示一个扩展是否被激活(使用),可以放在类定义和方法上,dubbo用它在spi扩展类定义上,表示这个扩展实现激活条件和时机. @Activate(group = Cons ...
- sqlserver2008r2实现镜像
拓扑图 环境 主服务器: 192.168.8.16 winserver2008b 镜像服务器 192.168.11.128 mssql1 见证服务器: 192.168.8.69 server2008c ...