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 ...
随机推荐
- FragmentTabHostBottomDemo【FragmentTabHost + Fragment实现底部选项卡】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 使用FragmentTabHost实现底部选项卡效果. 备注:该Demo主要是演示FragmentTabHost的一些设置和部分功能 ...
- TypeScript 中的方法重载
方法重载(overload)在传统的静态类型语言中是很常见的.JavaScript 作为动态语言, 是没有重载这一说的.一是它的参数没有类型的区分,二是对参数个数也没有检查.虽然语言层面无法自动进行重 ...
- 秋招已过,各大厂的面试题分享一波 附C++实现
数据结构和算法是面试的一座大山,尤其去面试大厂更是必不可少!简单说明一下为啥喜欢考数据结构和算法,首先,算法有用也没用,如果是中小型企业的简单业务逻辑,可能用不到啥算法,但大厂一定会用到,都知道数据库 ...
- 在AspNetMvc中使用日志面板. Logdashboard 1.1beta
Logdashboard 1.1beta. 在AspNetMvc中使用日志面板 Logdashboard是Net下的日志面板,它支持AspNet与AspNetCore项目.关于更多LogDashboa ...
- c#如何声明数据结构类型为null?
可以通过如下两种方式声明可为空的类型:System.Nullable<T> variable;T?variable:eg:int值是-2,147,483,648 到 2,147,483,6 ...
- Java笔记(day9~day10)
继承: 好处:1.提高代码复用性: 2.让类之间产生关系,给多态提供了前提: 父类.子类 Java中支持单继承,不直接支持多继承,但对C++的多继承进行了改良 单继承:一个子类只能有一个直接复类 ...
- Web前端-Ajax基础技术(上)
Web前端-Ajax基础技术(上) ajax是浏览器提供一套的api,用于向服务器发出请求,接受服务端返回的响应,通过javascript调用,实现通过代码控制请求与响应,实现网络编程. ajax发送 ...
- 自学MongoDB(1)
MongoDB是nosql(非关系型数据库)中的一种,面向文档的数据库,介于传统的结构化数据库(关系型数据库)与非关系型数据库(文件储存)之间的一种,具有数据结构非常松散和非常灵活的特点;常用于存储分 ...
- Mac Git 安装和配置
一.git下载与安装 点击Git,然后选择下载安装包 git --version,终端输入该命令, 如输出版本号,则说明安装成功. git version 2.20.1 二.git基本配置 通过下面这 ...
- 安装composer时,提示 /usr/bin/env: php: 没有那个文件或目录
今晚在Ubuntu环境上安装composer后,想查看下是否安装成功,使用composer -v,结果提示:/usr/bin/env: php: 没有那个文件或目录 现说说我的解决办法: 它提示的原因 ...