码迷,mamicode.com
首页 > 编程语言 > 详细

Java 编程

时间:2015-08-30 15:51:12      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Node{
	int x,y;
	int f;
	Node(){};
}
class Mycmp implements Comparator{
	public int compare(Object arg0, Object arg1){
		Node t1=(Node)arg0;
		Node t2=(Node)arg1;
		if(t1.x==t2.x) return t1.f>t2.f?1:-1;
		return t1.x>t2.x?1:-1;
	}
}
public class Main {
	public static void main(String[] args) {
		Node[] d=new Node[200010];
		for(int i=0;i<200010;++i)
			d[i] = new Node();
		Scanner cin = new Scanner(new BufferedInputStream(System.in));
		int T;
		T = cin.nextInt();
		int n,m;
		while(T!=0){
			T--;
			n = cin.nextInt(); m = cin.nextInt();
			int i;
			for(i=0;i<n;++i){
				d[i].x = cin.nextInt();
				d[i].y = cin.nextInt();
				d[i].f = 1;
			}
			for(;i<m+n;++i){
				d[i].x = cin.nextInt();
				d[i].y = cin.nextInt();
				d[i].f = 2;
			}
			Arrays.sort(d, 0, m+n, new Mycmp());
			BigInteger ans = BigInteger.valueOf(0);
			BigInteger numy = BigInteger.valueOf(0);
			for(i=0;i<n+m;++i){
				if(d[i].f==2) numy = numy.add(BigInteger.valueOf(d[i].y));
				else ans = ans.add(numy.multiply(BigInteger.valueOf(d[i].y)));
			}
			System.out.println(ans);
		}
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Java 编程

标签:

原文地址:http://blog.csdn.net/mengxingyuanlove/article/details/48105319

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!