Codeforces 215D. Hot Days(贪心)

题意
有nnn个地区和mmm个学生,在第iii个地区时,车上有kik_iki个学生,车内温度(当前城市的温度tit_iti+当前车上的学生kik_iki)不能超过TiT_iTi,否则,赔偿每个学生xix_ixi元,没经过一个地方,要花费costicost_icosti元,求通过nnn个地区所需要的最少花费(车上可以坐无限多的人,每经过一个地方,学生可以不坐在车上)
思路
- 如果当前城市的温度tit_iti高于TiT_iTi,那么不论车上有多少人,都需要进行赔偿,所以让所有的人都上车,进行一次赔偿,花费为costi+xi×mcost_i+x_i\times mcosti+xi×m
- 如果当前城市温度ti+m≤Tit_i+m\leq T_iti+m≤Ti,满足所有人都在车上,并且不需要进行赔偿,所以此时花费为costicost_icosti;
- 如果当前城市温度不超过TiT_iTi,但是当所有人都在车上时,温度超过了TiT_iTi,那么就要讨论是所有人在一辆车上一起通过还是在多辆车上,每辆车带的人数kkk满足k+ti≤Tik+t_i\leq T_ik+ti≤Ti这两种情况哪种花费少
AC代码
/*************************************************************************
> File Name: 215D.cpp
> Author: WZY
> QQ: 2697097900
> Created Time: 2018年12月04日 星期二 18时05分14秒
************************************************************************/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
ll t,T,x,cost;
ll ans=0;
for(int i=0;i<n;i++)
{
cin>>t>>T>>x>>cost;
ll tt=T-t;
// 情况一
if(tt<=0)
ans+=cost+x*m;
// 情况二
else if(tt>=m)
ans+=cost;
// 情况三
else
{
ll k=(m+tt-1)/tt;
ll res1=cost*k;
ll res2=cost+x*m;
ans+=min(res1,res2);
}
}
cout<<ans<<endl;
return 0;
}
Codeforces 215D. Hot Days(贪心)的更多相关文章
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
- CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...
- Codeforces 161 B. Discounts (贪心)
题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...
- CodeForces 176A Trading Business 贪心
Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
- Codeforces 486C Palindrome Transformation(贪心)
题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...
- Codeforces 1154D - Walking Robot - [贪心]
题目链接:https://codeforces.com/contest/1154/problem/D 题解: 贪心思路,没有太阳的时候,优先用可充电电池走,万不得已才用普通电池走.有太阳的时候,如果可 ...
- codeforces 735C Tennis Championship(贪心+递推)
Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C ——每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...
- CodeForces - 363D --二分和贪心
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...
随机推荐
- rest_framework视图和组件
一.视图 1.基本视图 #基本视图 #抽取基类 from rest_framework.response import Response from rest_framework.views impor ...
- jQuery学习笔记(一)
jQuery 事件 - ready() 方法 实例 在文档加载后激活函数(): $(document).ready(function(){ $(".btn1").click(fun ...
- Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包
B. Polygons time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- js 过滤器
,,]; ary[] = ; ary.filter(function(x) { return x === undefined; }); // A. [undefined x 7] // B. [0, ...
- CSS之user-select——设置标签中的文字是否可被复制
详细介绍请参考 http://www.css88.com/book/css/properties/user-interface/user-select.htm CSS样式 user-select:no ...
- itsdangerous
将字典进行加密.解密 通过私钥保证安全性 serializer=TimedJSONWebSignatureSerializer(私钥,过期时间) dumps(字典)=====>返回加密字符串 l ...
- 安卓constraintLayout中app:srcCompat设置的图片显示不出来
使用 app:srcCompat 的时候 引入的图片显示不出来的解决方案 首先查看的你的Activity 继承的是那个Activity 如果是继承AppcompatActivity 使用 Image ...
- js时间戳转化成日期格式
function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的 ...
- vscode ----> 学习笔记
java开发环境 jdk配置 maven配置 file --> preferences --> settings 在search settings搜索关键词 java.home , mav ...
- 『Python CoolBook』C扩展库_其二_demo演示
点击进入项目 C函数源文件 /* sample.c */ #include "sample.h" /* Compute the greatest common divisor */ ...