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 ...
随机推荐
- Android中怎么去除标题栏详解
怎么出去标题栏,我再另一个博客中亦有实例在这里再详细的解释一下,也让自己能更加巩固最简单也是小重要的东西. 这里有两种方法是比较好的... 第一种: 首先,在values中建一个theme.xml 代 ...
- 题目要求:建立一个类Str,将一个正整数转换成相应的字符串,例如整数3456转换为字符串"3456".
题目要求:建立一个类Str,将一个正整数转换成相应的字符串,例如整数3456转换为字符串"3456". 关键:怎么将一个数字转换为字符? [cpp] view plaincopy ...
- 微软Visual Studio "14" CTP 2 发布
微软Visual Studio "14" CTP 2 发布 对于在微软阵营下进行工作的团队来说,拥有最新版本的Visual Studio是提高效率最佳的选择,没有之一. 在本文中, ...
- Ajax提交底层原型XMLHttpRequest
相信接触过ajax的都觉得其post,get提交很方便,那么他是怎么实现的呢?基于此我们就不得不谈到js中的XMLHttpRequest对象. 其中w3c中是这样解释的: XMLHttpRequest ...
- REDGATE又一好用的脚本工具
REDGATE又一好用的脚本工具 REDGATE又一好用的脚本工具 先说明一下:这个工具是免费的 下载地址:http://www.red-gate.com/products/dba/sql-scr ...
- 协作图(通信图)collaboration diagram
协作图(通信图)collaboration diagram 系列文章 [UML]UML系列——用例图Use Case [UML]UML系列——用例图中的各种关系(include.extend) [UM ...
- 【NET】WebBrowser执行脚本以及一般操作代码
public class WebBrowserAssistant { System.Windows.Forms.WebBrowser wb; public WebBrowserAssistant(Sy ...
- springMVC3学习(十二)--文件上传优化CommonsMultipartResolver
基于上一篇文件上传发现效率很慢,我们应该对它进行优化 使用springMVC对文件上传的解析器 来处理文件上传的时候需要在spring的applicationContext里面加上springMVC ...
- IO多路复用之select
IO多路复用之select总结 1.基本概念 IO多路复用是指内核一旦发现进程指定的一个或者多个IO条件准备读取,它就通知该进程.IO多路复用适用如下场合: (1)当客户处理多个描述字时(一般是交 ...
- Linux操作系统学习_用户态与内核态之切换过程
因为操作系统的很多操作会消耗系统的物理资源,例如创建一个新进程时,要做很多底层的细致工作,如分配物理内存,从父进程拷贝相关信息,拷贝设置页目录.页表等,这些操作显然不能随便让任何程序都可以做,于是就产 ...