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 ...
随机推荐
- LindDotNetCore~Aspect面向方面编程
回到目录 Aspect面向方面编程 面向侧面的程序设计(aspect-oriented programming,AOP,又译作面向方面的程序设计.观点导向编程.剖面导向程序设计)是计算机科学中的一个术 ...
- 强化学习(四)用蒙特卡罗法(MC)求解
在强化学习(三)用动态规划(DP)求解中,我们讨论了用动态规划来求解强化学习预测问题和控制问题的方法.但是由于动态规划法需要在每一次回溯更新某一个状态的价值时,回溯到该状态的所有可能的后续状态.导致对 ...
- AR增强现实开发介绍(续)
AR增强现实开发介绍(续) ---开发基础篇 开发增强现实技术,无论是商业级应用,还是面向幼儿教育的游戏产品,都需要从了解.获取.下载增强现实插件开始.目前全世界使用量最大公认最好的增强现实插件是高通 ...
- ASP.NET Core 2.1的配置、AOP、缓存、部署、ORM、进程守护、Nginx、Polly【源码】
ps:废话不多说.直接上代码:源码地址:https://github.com/786744873/Asp.Net-Core-2.1-All-Demos/tree/master/src Configur ...
- WCF优雅使用 KnownType标记的方法
[KnownType("DerivedTypes")] [DataContract] public abstract class TaskBase { // other class ...
- qutebrowser 只用键盘操作的浏览器
一个 Qt 库制作的最简化浏览器,内核是 Chromium.最大特点就是它自带命令行,可以完全用键盘操作. 下载地址: 链接:https://share.weiyun.com/5Y2Ajvn 密码:m ...
- offsetLeft 解析
前言:先看下w3c与之相关的介绍: element.offsetHeight 返回元素的高度. element.offsetWidth 返回元素的宽度. element.offsetLeft 返回元素 ...
- 前端入门20-JavaScript进阶之异步回调的执行时机
声明 本系列文章内容全部梳理自以下几个来源: <JavaScript权威指南> MDN web docs Github:smyhvae/web Github:goddyZhao/Trans ...
- Android为TV端助力 Linux命令查看包名类名
先运行apk 再输入logcat | grep START 查看当前启动apk的包名和类名 adb shell "pm list packages -f | grep com.yulong. ...
- 问题解决--无法解析的外部符号 _imp_XXXXXXXXX
错误示例: 出现字符_imp,说明不是真正的静态库,而是某个动态库的导入库,导入函数和自己不同名,所以加了字符_imp.比如说_imp_GetUserNameA就是GetUserNameA函数. 会报 ...