struct root{
int x,y;
bool operator<(const root &a)const{
return a.y>a.x;
}
};
//两个变量的比较
struct root{
int x,y;
bool operator<(const root &a)const{
return a.y*x>a.x*y;
}
};
#include<bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
using namespace std;
const int maxn=10000;
//puts("First");
ll n,m;
struct root{
int x,y;
bool operator<(const root &a)const{
return a.y>a.x;
}
root(){cin>>x>>y;}
};
int main(){
int b=9;
root a[5];
sort(a,a+5);
for(int i=0;i<5;i++){
cout<<a[i].x<<" "<<a[i].y<<endl;
}
return 0;
}
- 搬出一个小题(加深印象):https://ac.nowcoder.com/acm/contest/329/D
- 代码:
-
#include<bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
using namespace std;
const int maxn=10000;
//puts("First");
ll n,m;
struct root{
ll x,y;
bool operator<(const root &a)const{
return y*a.x>x*a.y;
}
};
int main(){
ll n,sum=0,ans=0;cin>>n;
root a[n];
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y;
sum+=a[i].y;
}
sort(a,a+n);
for(int i=0;i<n;i++){
ans+=1ll*(sum-a[i].y)*a[i].x;
sum-=a[i].y;
}
cout<<ans<<endl;
return 0;
}