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. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  2. 如何在不接入微信API的情况下自定义分享内容(图片、链接、标题)

    方法如下: 1.设置分享title:动态改变document.title值即可: document.title = 'test' 2.设置分享图片:在页面隐藏一张尺寸大于290*290的图(图片需要容 ...

  3. Tomcat配置连接池的java实现

    1.准备 JNDI(Java Naming and Directory Interface),Java命名和目录接口.JNDI的作用就是:在服务器上配置资源,然后通过统一的方式来获取配置的资源.我们这 ...

  4. JavaScript对象中的constructor属性

    constructor属性始终指向创建当前对象的构造函数. 比如下面的例子: // 等价于 var foo = new Array(1, 56, 34, 12); var arr = [1, 56, ...

  5. unity3d之相机跟随人物

    一.第三人称视角 _1 先设置好相机与玩家之间的角度 给相机添加代码 using UnityEngine; using System.Collections; namespace CompletePr ...

  6. 使用模块化工具打包自己开发的JS库(webpack/rollup)对比总结

    打包JS库demo项目地址:https://github.com/BothEyes1993/bes-jstools 背景 最近有个需求,需要为小程序写一个SDK,监控小程序的后台接口调用和页面报错(类 ...

  7. Linux基础之命令练习Day4-fdisk,mkfs,mlabel,mount,umount,mkswap,swapon,dd,top,free,ps,kill,rpm,yum,make

    一. 硬盘分区.格式化及文件系统的管理 1. 在Linux系统中,一切皆文件.每个设备都被当作一个文件来对待. 常见的存储设备在Linux系统中的文件名如下表所示: 2. 对硬盘进行分区有以下优点: ...

  8. lua中使用table实现类和继承

    --因为只有当读写不存在的域时,才会触发__index和__newindex classA = {className = "classA",name="classAIns ...

  9. P4python: python interface to Perforce API

    P4python is the python interface to Perforce API, it helps to do Perforce operations through python. ...

  10. c# 读取txt文件并分隔

    public static List<PostPerson> GetNameByFile() { #region 读取txt文件 var file = File.Open(Environm ...