0
已解决
赵逸凡
初级启示者
初级启示者
#include<bits/stdc++.h>
using namespace std;
namespace fastIO
{
#define BUF_SIZE 100000
bool IOerror=0;
inline char nc()
{
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend)
{
p1=buf;
pend=buf+fread(buf,1,BUF_SIZE,stdin);
if(pend==p1)
{
IOerror=1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch)
{
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
inline void read(int &x)
{
char c;
while(blank(c=nc()));
if(IOerror) return;
for(x=c-'0';(c=nc())>='0'&&c<='9';x=x*10+c-'0');
}
#undef BUF_SIZE
};
long long n,ans;
typedef long long ll;
struct io
{
int x,y;
} a[50000];
inline bool cmp(io a,io b)
{
return a.x<b.x;
}
inline void write(long long x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)write(x/10);
putchar(x%10+'0');
}
int main()
{
cin>>n;
for(register int i=1;i<=n;i++)
fastIO::read(a[i].x),fastIO::read(a[i].y);
sort(a+1,a+n+1,cmp);
for(register int i=2;i<=n;i++)
for(register int j=1;j<i;j++)
ans+=a[i].x*abs(a[i].y-a[j].y);
write(ans);
return 0;
}
思路:模拟,卡常
有啥优化算法吗,为什么1分