One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
3 1 10 5 5 10 1
75 110 60
3 2 1 1 2 2 1
6 4 6
题意: n个人合影。输入这n个人,下面n行,每一行输入这个人占据照片的宽高。要求输出n个数。第i个数表示照片去掉第i个人所需要的总宽高。高肯定是剩下几个人的高度的 最大值,宽度肯定是剩下那几个人的宽度之和喽。
分析:输出问题有很多,n的规模也比较大,所以我就边输入边计算,找到总的高度最大值和次大值,并计算所有宽度的和。输出的时候,判断最大高度是否就一个人,这里用个flag就可以了。如果第i个人高度与最大高度相同而且flag显示只有一个高度最大的,输出高度次大值(次大值就这么点用了)。其余就输出最大值楼=喽。最后别忘了与总宽度减去自身宽度相乘。
这个代码有点问题,我懒得改了,因为太明显。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
#include <map>
using namespace std;
//522B implement
int num[200001][2];
int main()
{
int n;
int sum=0;
cin>>n;
cin>>num[0][0]>>num[0][1];
cin>>num[1][0]>>num[1][1];
int max=num[0][1]>num[1][1]?num[0][1]:num[1][1];
int max2=num[0][1]<num[1][1]?num[0][1]:num[1][1];
int maxnum=num[0][1]>num[1][1]?0:1;
int max2num=num[0][1]<num[1][1]?0:1;
sum+=num[0][0];
sum+=num[1][0];
for(int i=2;i<n;i++)
{
cin>>num[i][0]>>num[i][1];
sum+=num[i][0];
if(num[i][1]>max2)
{
swap(num[i][1],max2);
max2num=i;
}
if(max2>max)
{
swap(max,max2);
swap(maxnum,max2num);
}
}
//cout<<max<<" "<<maxnum<<" "<<max2<<" "<<max2num<<endl;
for(int i=0;i<n;i++)
{
if(i==maxnum||num[i][1]==max)
{
cout<<max2*(sum-num[i][0])<<" ";
}
else
{
cout<<max*(sum-num[i][0])<<" ";
}
}
return 0;
}