FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)

Time Limit: 1000MS   Memory Limit: 257792K

【Description】

【题目描述】

Fat Brother is a powerful magician. Both he and his enemy has N soldiers and each soldier has IQ. When two soldier is in PK, the one whose IQ is exactly higher than the another one will win. He can use ruozhi magic to decrease his enemy’s soldiers’ IQ, using ruozhi magic one time, all of his enemy’s soldiers’ IQ will decrease 1. Fat Brother is a perfectionists, so he want his all soldiers to win and uses ruozhi magic at least the number of times. So you should help Fat Brother calculate how many times he should use ruozhi magic?

胖哥是一位强力法师。他和他的敌人都有N个小兵,每个小兵拥有一定IQ。当小兵两两PK时,IQ较高者胜。他能用弱智术减少敌方小兵的IQ,弱智术每次能减少1点敌方所有小兵的IQ。胖哥是个完美主义者,因此他希望己方小兵完胜并尽可能少地使用弱智术。所以就由你来帮胖哥算算他最少需要使用的弱智术的次数是多少?

【Input】

【输入】

There are multiple test cases. The first line of input contains an integer T (T <= 20) indicating the number of test cases. For each test case:

The first line contains one integer N (1 <= N <= 100000) means number of soldiers.

The next line contains N number Ai means Fat Brother’s soldiers IQ,

The next line contains N number Bi means enemy’s soldiers IQ,

Ai and Bi fit in 32-bits signed integer

多组测试用例。

第一行是一个整数T(T <= 20)表示测试用例的数量。对于每个测试用例:

第二行是一个整数N(1 <= N <= 100000)表示小兵的数量。

下一行有N个数Ai,表示胖哥小兵的IQ。

下一行有N个数Bi,表示胖哥小兵的IQ。

Ai与Bi在32为整数间。

【Output】

【输出】

Each case print a number means at least the number of times Fat Brother should use ruozhi magic

每个用例输出胖哥弱智术的最小使用次数。

【Sample Input - 输入样例】

【Sample Output - 输出样例】

2

5

1 3 2 4 5

3 3 3 3 3

3

2 -9 -5

5 -2 -7

3

4

【Hint】

【提示】

First

case, use 3 times ruozhi magic, his enemy’s soliders’ IQ will

become 0 0 0 0 0, all enemy’s soliders’ IQ lower than Fat Brother’s, So all Fat Brother’s soliders will win

Second

case, use 4 times ruozhi magic, his enemy’s soliders’ IQ will

become 1 -6 -11, So Fat Brother’s first solidier win enemy’s first solidier, second win third, third win second.

第一个用例,

使用3此弱智术,敌方小兵IQ将变成0 0 0 0 0,所有敌方小兵的IQ低于胖哥的,因此己方小兵获胜。

第二个用例,

使用4次弱智术,敌方小兵IQ将变成1 -6 -11,使用胖哥的第一个小兵完胜敌方第一个,第二个完胜第三个,第三个完胜第二个。

【题解】

从测试样例可以看出我方拥有其两两PK的选择权,又需要全胜,因此上等马VS上等马,下等马VS下等马,排个序就好了。

【代码 C++】

 #include<cstdio>
#include <algorithm>
#define LL long long
LL s1[], s2[];
int main(){
int t, n, i;
LL sum;
while (~scanf("%d", &t)){
while (t--){
scanf("%d", &n);
for (i = ; i < n; ++i) scanf("%lld", &s1[i]);
for (i = ; i < n; ++i) scanf("%lld", &s2[i]);
std::sort(s1, s1 + n); std::sort(s2, s2 + n);
for (i = sum = ; i < n; ++i){
if (s1[i] + sum <= s2[i]) sum += s2[i] - s1[i] - sum + ;
}
printf("%lld\n", sum);
}
}
return ;
}

FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)的更多相关文章

  1. FJNU 1153 Fat Brother And XOR(胖哥与异或)

    FJNU 1153 Fat Brother And XOR(胖哥与异或) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] ...

  2. FJNU 1155 Fat Brother’s prediction(胖哥的预言)

    FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  3. FJNU 1152 Fat Brother And Integer(胖哥与整数)

    FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题 ...

  4. FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

    FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目 ...

  5. FJNU 1151 Fat Brother And Geometry(胖哥与几何)

    FJNU 1151 Fat Brother And Geometry(胖哥与几何) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  6. FJNU 1154 Fat Brother And His Love(胖哥与女神)

    FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS   Memory Limit: 257792K [Description] [ ...

  7. FJNU 1159 Fat Brother’s new way(胖哥的新姿势)

    FJNU 1159 Fat Brother’s new way(胖哥的新姿势) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目 ...

  8. HDU 4637 Rain on your Fat brother 线段与半圆和线段交 简单题

    题意: 应该不难读懂. 做法: 我们可以把雨滴看做静止不动,然后maze(这题的那个人)就是往左上方运动就可以了,计算出maze能跑到的最远的点,然后就是求起点和终点所构成的线段与每个雨滴交的时间,注 ...

  9. 大数据的胖哥的方式(9)- 金融业数据仓库的逻辑模型FS-LDM

    介绍: 大数据是不是海市蜃楼,来自小橡子只是意淫奥克斯,大数据的发展,而且要从头开始,基于大数据建设国家.项目-level数据中心行业将越来越多,大数据仅供技术,而非溶液,临数据组织模式,数据逻辑模式 ...

随机推荐

  1. shell 在文件名后面添加特定数据

    for a in `ls mo-*`;do mv ${a%:} ${a%:}-1;done

  2. USB HID描述符【转】

    本文转载自: USB是个通用的总线,端口都是统一的.但是USB设备却各种各样,例如USB鼠标,USB键盘,U盘等等,那么USB主机是如何识别出不同的设备的呢?这就要依赖于描述符了.USB的描述符主要有 ...

  3. 【secureCRT】永久设置背景色和文字颜色

  4. tomcat缓存静态资源深入

    之前看过apach及nginx对于静态资源(含js,图片,css等)部分的缓存,用于加速并减轻后台实际web服务器的压力. 静态资源缓存是WEB服务器优化的一种手段,基本原理如下: 1.客户端浏览器请 ...

  5. SpringMVC整合TaskExecutor线程池的配置/使用

    一.配置jdbc.properties添加: #------------ Task ------------ task.core_pool_size=5 task.max_pool_size=50 t ...

  6. 【Pro ASP.NET MVC 3 Framework】.学习笔记.3.MVC的主要工具-单元测试

    IProductRepository接口定义了一个仓库,我们通过它获得.更新Product对象.IPriceReducer接口指定了一个功能,它将要对所有的Products实施,通过一个参数,降低他们 ...

  7. 微信清理H5真的太早了?这会是应用号发布的前兆吗

    三少爷的剑  2016-04-18 21:05 收藏35 评论7   两天之内,整个 H5 游戏创业陷入了两年狂热期以来最冷的冰点. 每一个正在忙于 H5 小游戏开发的开发者都在忙于砍掉游戏代码中有关 ...

  8. windows7配置Nginx+php+mysql的详细操作是怎样?

    1.准备安装包等 (1)nginx-1.10.1.zip,下载链接为http://nginx.org/en/download.html .我个人选择了稳定版. (2)php-5.6.25-nts-Wi ...

  9. RAC例子

    我个人非常推崇ReactiveCocoa,它就像中国的太极,太极生两仪,两仪生四象,四象生八卦,八卦生万物.ReactiveCocoa是一个高度抽象的编程框架,它真的很抽象,初看你不知道它是要干嘛的, ...

  10. HDU 1269:迷宫城堡(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=1269 题意:确定是否是一个强连通图. 思路:裸的tarjan算法. #include <cstdio> ...