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. [tools]转载汇总

    1. 发送请求工具—Advanced REST Client Advanced REST Client是Chrome浏览器下的一个插件,通过它可以发送http.https.WebSocket请求.

  2. [H5表单]一些html5表单知识及EventUtil对象完善

    紧接着上面的文章,一开始准备一篇文章搞定,后来看到,要总结的东西还不少,干脆,把上面文章拆成两部分吧,这部分主要讲讲表单知识! 表单知识 1.Html5的autofocus属性. 有个这个属性,我们不 ...

  3. jQuery ajax async

    jQuery 同步调用: jQuery.ajax({ type:'POST', async: false, url:'qcTask/add', contentType:'application/jso ...

  4. PS基础,英语

    PS基础(矢量图案的绘制) 水平参考线:新建背景(长宽一致,背景内容为透明)---设置水平参考线(水平垂直都要)---完成. 背景制作:设置前景色---用矩形选框工具绘制正方形选区(背景已被参考线平分 ...

  5. java向上转型的问题

    import java.util.Arrays;import java.util.HashSet;import java.util.Set;class A{ private String s1 = & ...

  6. JavaScript十大古怪之处(出自众妙之门)

    1. null是一个对象: alert(typeof null);  //objects NULL表示没有值,那么很明显他不能作为任何东西的实例,所以下式应该等于false: alert(null i ...

  7. 一、mysql架构

    一.简介 mysql是一个开源的数据库管理系统,它相对于oracle更加地轻量.成本低,随着功能的日益完善,它变得备受企业喜爱,尤其是中小企业. mysql的整体架构大体包括以下几个方面: 1)主体结 ...

  8. rabbit工作队列模式

    工作队列比简单队列在消费者这边多了一个方法. channel.basicQos(1);公平队列消费(参数设置为1,表示消费者消费完一条才会去接受再次发来的消息) 生产者: package com.kf ...

  9. 前端(一):html标签

    HTML(Hypertext Markup Language)超文本标记语言,它负责页面的结构.超文本指的是超链接,使用超链接可以从一个页面跳转到另一个页面. HTML的发展:1993年6月发布第一个 ...

  10. hdu 3091 Necklace 状态压缩dp *******

    Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total ...