CodeForces 1151D Stas and the Queue at the Buffet
题目链接:http://codeforces.com/contest/1151/problem/D
题目大意:
有n个学生排成一队(序号从1到n),每个学生有2个评定标准(a, b),设每个学生的位置为j,则每个学生所要交的学费为a * (j - 1) + b * (n - j),要求把这些学生从新排序使得整体所交学费最小。
分析:
代码如下:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std; #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef set< int > SI;
typedef vector< int > VI;
typedef map< int, int > MII;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; LL n, ans; struct Student{
LL a, b; LL disSa(int x) const {
return a * (x - ) + b * (n - x);
}
}; Student stu[maxN]; bool cmp(const Student &x, const Student &y) {
return x.a - x.b > y.a - y.b;
} int main(){
INIT();
cin >> n;
For(i, , n) cin >> stu[i].a >> stu[i].b; sort(stu + , stu + n + , cmp); For(i, , n) ans += stu[i].disSa(i);
cout << ans << endl;
return ;
}
CodeForces 1151D Stas and the Queue at the Buffet的更多相关文章
- Codeforces Round #553 (Div. 2) D. Stas and the Queue at the Buffet 贪心+公式转化
题意 给出n个pair (a,b) 把它放在线性序列上 1--n 上 使得 sum(a*(j-1)+b*(n-j)) 最小 思路 :对式子进行合并 同类项 有: j*(a-b)+ (-a+ ...
- B类——Stas and the Queue at the Buffet
http://codeforces.com/contest/1151/problem/D 题意: n个学生,每个学生都有自己的位置,最后要使
- 洛谷 题解 CF1151D 【Stas and the Queue at the Buffet】
本蒟蒻又双叒叕被爆踩辣!!! 题目链接 这道题我个人觉得没有紫题的水平. 步入正题 先看题: 共有n个人,每个人2个属性,a,b; 窝们要求的是总的不满意度最小,最满意度的公式是什么? \(ai * ...
- CodeForces Round #553 Div2
A. Maxim and Biology 代码: #include <bits/stdc++.h> using namespace std; int N; string s; int mi ...
- Codeforces Round #553 (Div. 2) 题解
昨晚深夜修仙上紫记,虽然不错还是很有遗憾的. A. Maxim and Biology 看完就会做的题,然而手速跟不上 #include<cstdio> #include<iostr ...
- Codeforces Round #553 (Div. 2)/codeforces1151
CodeForces1151 Maxim and Biology 解析: 题目大意 每次可以使原串中的一个字符\(+1/-1\),\(Z + 1\to A, A -1\to Z\),求至少修改多少次可 ...
- codeforces 1151 D
SM的水题. codeforces 1151D 当时写对了,因为第一题卡了,,然后这题就没细想,原来是没开longlong. 题意:n个位置每个位置有a和b,让sum=(每个点的左面的点的数量*a+右 ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树+二分
B. Queue Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/91/B Descrip ...
随机推荐
- 《前端之路》之五 head 头标签指南
12:head 头标签指南 常见头标签 DOCTYPE 文档模式 对文档进行有效性验证 告诉用户代理或浏览器这个文档是按照什么DTD写的,但是这个动作是被动的,每次页面加载时,浏览器并不会下载DTD, ...
- Locust性能测试学习总结
Locust学习总结分享 简介: Locust是一个用于可扩展的,分布式的,性能测试的,开源的,用Python编写框架/工具,它非常容易使用,也非常好学.它的主要思想就是模拟一群用户将访问你的网站.每 ...
- SLAM+语音机器人DIY系列:(三)感知与大脑——6.做一个能走路和对话的机器人
摘要 在我的想象中机器人首先应该能自由的走来走去,然后应该能流利的与主人对话.朝着这个理想,我准备设计一个能自由行走,并且可以与人语音对话的机器人.实现的关键是让机器人能通过传感器感知周围环境,并通过 ...
- [TCP/IP] 传输层-ethereal 抓包分析TCP包
开启抓包工具抓取一个HTTP的GET请求,我的ip是10.222.128.159 目标服务器ip是140.143.25.27 握手阶段: 客户端 ===> SYN MSS=1460(我能接 ...
- Yii2设计模式——单例模式
应用举例 在Yii.php中: require __DIR__ . '/BaseYii.php'; // Yii框架的帮助类,提供框架基本的功能 class Yii extends \yii\Base ...
- 非常易于理解‘类'与'对象’ 间 属性 引用关系,暨《Python 中的引用和类属性的初步理解》读后感
关键字:名称,名称空间,引用,指针,指针类型的指针(即指向指针的指针) 我读完后的理解总结: 1. 我们知道,python中的变量的赋值操作,变量其实就是一个名称name,赋值就是将name引用到一个 ...
- java反序列化漏洞实战
准备: 域名一个,用于增加NS解析,判断是否存在反序列化漏洞. 公网IP服务器一台,用于搭建DNS代理,抓包判断. dnschef,DNS代理 ysoserial.jar生成payload. 简单的p ...
- 前端页面基于JQuery的点击事件
一,使用id选择器 1.方式一 $("#id").click(function(){ do something }) 2.方式二 $("#id").on(&qu ...
- Django用户继承AbstractUser后密码为明文
Django用户继承AbstractUser后密码为明文 其实本不应该有这个问题,却花了我很久的时间,因为还是初学阶段. 造成这个原因是因为在admin注册的生活没有指定Admin 在app的admi ...
- (七) Keras 绘制网络结构和cpu,gpu切换
视频学习来源 https://www.bilibili.com/video/av40787141?from=search&seid=17003307842787199553 笔记 首先安装py ...