Kattis - Biased Standings
Biased Standings
Usually, results of competitions are based on the scores of participants. However, we are planning a change for the next year of IPSC. During the registration each team will be able to enter a single positive integer – their preferred place in the ranklist. We would take all these preferences into account, and at the end of the competition we will simply announce a ranklist that would please all of you.
But waitHow would that ranklist look like if it won’t be possible to satisfy all the requests?
Suppose that we already have a ranklist. For each team, compute the distance between their preferred place and their place in the ranklist. The sum of these distances will be called the badness of this ranklist.
Given team names and their preferred placements find one ranklist with the minimal possible badness.
Input
The first line of the input file contains an integer T,T≤20T,T≤20, specifying the number of test cases. Each test case is preceded by a blank line.
Each test case looks as follows: The first line contains an integer N(N≤100000)N(N≤100000) – the number of teams participating in the competition. Each of the next NN lines contains a team name (a string of letters and numbers of length at most 20) and its preferred place (an integer between 1 and NN, inclusive). No two team names will be equal.
Output
For each of the test cases output a single line with a single integer – the badness of the best ranklist for the given teams.
| Sample Input 1 | Sample Output 1 |
|---|---|
2 7 |
5 |
题意
给出队名,首选位置,然后给他们排一个实际的表,求实际位置和首选位置的差值和最小
思路
代码
#include<bits/stdc++.h>
using namespace std;
#define LL long long
struct Node{
string s;
int id;
int num;
}aa[];
bool cmp(Node a,Node b){
return a.num<b.num;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
LL sum=;
for(LL i=;i<n;i++){
cin>>aa[i].s>>aa[i].num;
}
sort(aa,aa+n,cmp);
for(LL i=;i<n;i++){
aa[i].id=i+;
sum+=abs(aa[i].id-aa[i].num);
}
cout<<sum<<endl;
}
return ;
}
Kattis - Biased Standings的更多相关文章
- ural 1100. Final Standings(数据结构)
1100. Final Standings Time limit: 1.0 secondMemory limit: 16 MB Old contest software uses bubble sor ...
- Java偏向锁实现原理(Biased Locking)
http://kenwublog.com/theory-of-java-biased-locking 阅读本文的读者,需要对Java轻量级锁有一定的了解,知道lock record, mark wor ...
- It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld (等差数列求和取模)
题目链接: D - It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld 具体的每个参数的代表什么直接看题面就好了. AC代码: ...
- A - Piece of Cake Kattis - pieceofcake (数学)
题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面 ...
- Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)
题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...
- G - Intersecting Rectangles Kattis - intersectingrectangles (扫描线)(判断多个矩形相交)
题目链接: G - Intersecting Rectangles Kattis - intersectingrectangles 题目大意:给你n个矩形,每一个矩形给你这个矩形的左下角的坐标和右上角 ...
- E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)
题目链接: E - Emptying the Baltic Kattis - emptyingbaltic 题目大意:n*m的地图, 每个格子有一个海拔高度, 当海拔<0的时候有水. 现在在(x ...
- G - Galactic Collegiate Programming Contest Kattis - gcpc (set使用)
题目链接: G - Galactic Collegiate Programming Contest Kattis - gcpc 题目大意:当前有n个人,一共有m次提交记录,每一次的提交包括两个数,st ...
- JVM内部细节之二:偏向锁(Biased Locking)
在前面一片文章<JVM内部细节之一:synchronized关键字及实现细节>中已经提到过偏向锁的概念,在理解什么是偏向锁前必须先理解什么是轻量级锁(Lightweight Locking ...
随机推荐
- javascript模拟title提示效果
本代码可以实现如下情况: 1.js实现title是为了解决自定义样式和格式! 2.希望传入的格式可以不限制是否包含html结构! 3.可以自定义显示层的位置! js如下: function GetAb ...
- struts2 <s: select 标签值
JSP页面: <s:select label="家长导航" value="id" name="navson.pid" list=&q ...
- Mysql高级之主从复制
原文:Mysql高级之主从复制 主从复制不就是多台服务器嘛!,一个改变另一个也改变啦,内容其实都一样! 原理: 对数据库进行操作会生成一个文件,binlog(二进制文件),从服务器配置relaylog ...
- Nexus入门指南(图文)
Nexus入门指南(图文) 博客分类: Maven JavamavenGoogleApacheTomcat Nexus介绍 Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven ...
- 在PHP中连接数据库时获取最后的一个ID
在SQL中获取最后的一个id 只需要加上where条件对id进行排序就可以了 但是在PHP中 有一种最新的方法 使用mysql_insert_id();就可以获得最大的id .
- 自己动手实现Expression翻译器 – Part Ⅱ
上一节我们了解了Linq查询大体上是如何运转的,并针对SQL表达式进行建模(DbExpression),这一节的重点在于如何将表达式转换为DbExpression. 可以说只要能生成结构清晰的DbEx ...
- document对象属性documentMode与CompatMode
DOCTYPE DOCTYPE全称Document Type Declaration(文档类型声明,缩写DTD) DTD的声明影响浏览器对于CSS代码及Javascript脚本的解析. 渲染模式 渲染 ...
- MVC 控制器
ASP.NET MVC控制器(一) 前言 在路由的篇章中讲解了路由的作用,讲着讲着就到了控制器部分了,从本篇开始来讲解MVC中的控制器,控制器是怎么来的?MVC框架对它做了什么?以及前面有的篇幅所留的 ...
- linux find命令之exec
find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是command ...
- mac下Android apk 破解流程
相关工具下载:http://pan.baidu.com/s/1kTkOicn 首先你要有eclipse工具,在sdk目录下有如下工具可以使用 android:adb shell:进入交互shell ...