Codeforces Round #437 (Div. 2)

codeforces 867 A. Between the Offices(水)

题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从西雅图飞到旧金山次数更多。

题解:只要判断第一天和最后一天状态即可。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
int n;
char s[N];
int main() {
scanf("%d %s", &n, s);
if(s[] == 'S' && s[n-] == 'F') puts("YES");
else puts("NO");
return ;
}

15ms

codeforces 865 A. Save the problem!(构造)

题意:原本是知道所需钱数和有多少种类的面额以及各面额的价值,要求有多少种方式可以从给定的面额中选取若干拼成所需的钱数,,现在反过来已知多少方式,来构造输入样例。

题解:直接用1和2面额来拼。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int main() {
scanf("%d", &n);
printf("%d 2\n1 2\n", (n-)*+);
return ;
}

15ms

codeforces 865 B. Ordering Pizza(贪心)

题意:有两种类型的披萨,已知有N个人要吃披萨,每块披萨有S片;第i个人吃si片,如果吃类型1,每片能获得ai幸福度,吃类型2则是bi幸福度。现在要购买最少数量的披萨满足N个人所需的数量,并求能获得的最大幸福度。

题解:贪心吃幸福度大的类型,记录1、2类型最优各吃几片,如果1、2类型披萨所需数量之和≤总共所需披萨数量,则直接输出答案,否则给 1和2类型幸福度差值较小的赋予高优先级,排序后 将多余的1类型换成2类型披萨,或2换成1,以满足最少数量披萨数目。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5+;
ll n, S;
ll s[N],a[N],b[N];
struct node {
ll x;
int id;
bool operator < (const node&r)const{
return x < r.x;
}
}c[N];
int main() {
int i, f = ;
ll ans = , sum = , a1=, a2=;
ll s1=, s2=;
scanf("%lld %lld", &n, &S);
for(i = ; i <= n; ++i) {
scanf("%lld %lld %lld", &s[i], &a[i], &b[i]);
if(a[i] > b[i]) s1 += s[i];
else if(a[i] < b[i]) s2 += s[i];
sum += s[i];
ans += max(a[i], b[i]) * s[i];
c[i].x = a[i] - b[i]; c[i].id = i;
}
ll cnt = (sum + S-) /S;
if((s1 + S-)/S + (s2 + S-)/S <= cnt) {printf("%lld", ans); return ;}
sort(c+, c++n);
s1 %= S; s2 %= S;
for(i = ; i <= n; ++i) {
if(c[i].x <= ) {f = i; continue;}
if(!s1) break;
ll t = min(s[c[i].id], s1);
a1 += t * c[i].x;
s1 -= t;
}
for(i = f; i >= ; --i) {
if(!c[i].x) continue;
if(!s2) break;
ll t = min(s[c[i].id], s2);
a2 -= t * c[i].x;
s2 -= t;
}
printf("%lld\n", ans - min(a1, a2));
return ;
}

78ms

codeforces 865 D. Buy Low Sell High(优先队列,模拟)

题意:知道N天的股票的价格,一开始有0股,每天可以买一股或卖一股或什么都不做,要在N天后继续是0股,但希望在这N天内赚尽量多的钱。

题解:开个优先队列模拟。注意优先队列默认数据大的优先级高,所以加个负号。

比队首大的值要插入两遍,一是为了给前面小的值升值,二是为了将自己插入队列等待被买入。比如:4、7、9,4被升值为7进而被升值为9(实际选择是-4+9),第二步取出的一个7是为了给4进一步升值,7还要有一个在队列中等待被买入。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int> q;
int main() {
int i, n, x;
long long ans = ;
scanf("%d", &n);
q.push(-);
for(i = ; i <= n; ++i) {
scanf("%d", &x);
if(-q.top() < x) {
ans += x + q.top(); q.pop(); q.push(-x);
}
q.push(-x);
}
printf("%lld", ans);
return ;
}

108ms

Codeforces Round #437 (Div. 2)[A、B、C、E]的更多相关文章

  1. Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)

    主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...

  2. 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza

    [链接]h在这里写链接 [题意]     给你参赛者的数量以及一个整数S表示每块披萨的片数.     每个参数者有3个参数,si,ai,bi;     表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...

  3. Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)

    http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 ...

  4. Codeforces Round #437 Div. 1

    A:显然构造一组只包含1和2面值的数据即可. #include<iostream> #include<cstdio> #include<cmath> #includ ...

  5. Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)

    Problem A Between the Offices 水题,水一水. #include<bits/stdc++.h> using namespace std; int n; ]; i ...

  6. Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E

    题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同: 题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相 ...

  7. 【Codeforces Round #437 (Div. 2) A】Between the Offices

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...

  8. 【Codeforces Round #437 (Div. 2) B】Save the problem!

    [链接]h在这里写链接 [题意]     给你一个金额N,和硬币的类型总数M;     (完全背包),然后问你组成N的方案数.     使得,用这些硬币组成价值为N的金额的方案数为A;     现在A ...

  9. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

随机推荐

  1. poj 2105 IP Address

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18951   Accepted: 10939 Desc ...

  2. KVC的特殊用法

    - (id)valueForKeyPath:(NSString *)keyPath方法的强大用法,举个例子: NSArray *array = @[@"name", @" ...

  3. Echarts 修改折线的颜色和折线的点的大小方法

    series: [{ type: 'line', smooth:true,//折点是圆弧状的                            showSymbol: true,          ...

  4. nodejs中cookie、session的使用

    因为http会话的无状态性,为了标记用户的登录状态,便出现了cookie.cookie分为很多种,有普通cookie.签名cookie.json cookie等,这里主要记录下在express应用中如 ...

  5. php strpos返回字符串首次出现的位置

    (PHP 4, PHP 5, PHP 7) strpos — 查找字符串首次出现的位置 说明 mixed strpos ( string $haystack , mixed $needle [, in ...

  6. 在linux命令行利用SecureCRT上传下载文件

    一般来说,linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使用ssh登陆linux主机以后,如何能够快速的和本地机器进行文件的交互呢,也就是上传和下载文件到服务器和本地?与ssh有关的 ...

  7. 无法解析 id,或者它不是字段

    解决方法:首先,看下R文件,有没有你上面的ID.没有的话,点项目-clean . 有的话,估计你是导了android里面的那个R包了,你看看你导的包有木有 “import android.R”有的话去 ...

  8. 工厂模式的C++、Java实现

    1.工厂模式UML 图1. 工厂模式UML 2.C++实现 类视图如下: 图2. 工厂模式C++实现的类图 其中,Factory实现为: //工厂类. class Factory { public: ...

  9. 远程连接Redis服务器

    建立了一个redis服务器,那么其他主机应该怎么连接上呢? /** * * 修改redis.conf配置文件 * */ // 1. 注释掉bind绑定配置 // 2. 搜索并修改为 protected ...

  10. css移动端:acitve效果的实现

    做移动前端也有一些日子了,一直有个问题没有解决,就是与pc端那样的一个:hover的效果,:hover是鼠标指针浮动在其上的元素的一个选择器,但因为在移动端是没有鼠标的,代替的是触摸屏,用户也不是有“ ...