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. WPF的布局--StackPanel

    1. StackPanel是以堆叠的方式来显示控件(从左到右,或者从上到下) 默认是从上到下显示的,并且宽度为StackPanel的宽度,高度自动适应控件中内容的高度(未对控件进行设置时) 如图: 代 ...

  2. resteasy上传单个文件/多个文件到阿里云服务器

    代码如下: ExcelServerController.java package com.xgt.controller; import com.xgt.bean.bs.ExcelBean; impor ...

  3. Django models.py创建数据库

    创建完后初始化数据库 在命令行里输入: 回车后出现 继续命令行输入:

  4. 如何限制html标签input的长度

    如何限制html标签input的长度 示例: <form action="/example/html/form_action.asp" method="get&qu ...

  5. [转]MSBuild Target Framework and Target Platform

    本文转自;https://msdn.microsoft.com/en-us/library/hh264221.aspx A project can be built to run on a targe ...

  6. Change - Why we need coding standards

    Change - Why we need coding standards I have the idea of coding standards when I have to review my t ...

  7. 定时器setTimeout()和setInterval()使用心得整理

    JavaScript提供定时执行代码的功能,叫做定时器(timer),主要由setTimeout()和setInterval()这两个函数来完成. 一.setTimeout() setTimeout函 ...

  8. [android] socket在手机上的应用

    1.手机助手 1.1 USB链接 可以读取手机的PID和VID,确定唯一的设备,可以给手机安装对应的驱动等 socket在固定端口通信 1.2 WIFI链接 pc在电脑在整个网段发送UDP数据包,手机 ...

  9. [shell]管理 Sphinx 启动|停止|重新生成索引的脚本

    对于启动sphinx的服务,可以直接输入如下命令 /usr/bin/searchd -c /etc/sphinx/sphinx.conf <!-- /usr/local/bin/searchd  ...

  10. dategrid快速录入一行数据的一波操作

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...