题意:
给你n个人的成绩和改变值,问你安排一种改变的顺序使得n个人的名次变化和最大
思路:
n^2枚举每两个人之间名次的变化对结果带来的影响就可以了
/* *********************************************** Author :devil ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <stack> #include <map> #include <unordered_map> #include <string> #include <time.h> #include <cmath> #include <stdlib.h> #define LL long long #define rep(i,a,b) for(int i=a;i<=b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define ou(a) printf("%d\n",a) #define pb push_back #define pii pair<int,int> #define mkp make_pair #define IN freopen("in.txt","r",stdin); #define OUT freopen("out.txt","w",stdout); using namespace std; const int inf=0x3f3f3f3f; const int mod=1e9+7; const int N=1e2+10; int n,ans,ans2; pii a[N],b[N]; bool ok(pii x,pii y,pii z) { if(x>z) swap(x,z); return x<y&&y<z; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&a[i].first,&b[i].first),b[i].first+=a[i].first,a[i].second=-i,b[i].second=-i; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { int p=ok(a[i],a[j],b[i])+ok(a[j],b[i],b[j]); if(p==2) ans+=2;else ans2+=p; } printf("%d\n",ans+ans2/2); return 0; }
时间: 2024-10-22 08:38:07