南京理工大学校赛J题

题目:点击打开链接

这是个水题,最后计算空余地区的面积即可,,用总面积减去输入的区域面积,就能得到所要求的面积,(但是这道题十分神奇就是有时wa,有时ac,,思想是对的)

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>                      
#include <map>
#include <vector>
#include <cmath>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1                                  
using namespace std;
const int maxn = 155555;
typedef unsigned long long  LL;
LL hh[maxn],ll[maxn];

LL maxx(LL A, LL B)
{
	return A > B ? A : B;
}
int main(void)
{
	//freopen("in.txt", "r", stdin);
	LL N;

	while (scanf("%llu", &N) != EOF)
	{
		if (N == 0)
		{
			printf("1\n");
			continue;
		}
		LL sum = 0,h = 0,l = 0;
		int i, j;
		LL H, W;
		for (i = 0; i < N; i++)
		{
			cin >> H >> W;
			hh[i] = H;
			ll[i] = W;
			h = max(h, H);
			l += W;
		}
		h++;
		LL area = 0;
		for (i = 0; i < N; i++)
		{
			area =  area+(h - hh[i])*ll[i];
		}
		cout << area << endl;
	}
	return 0;
}

你可能感兴趣的:(南京理工大学校赛J题)