Codeforces Round #622 Problem B Different Rules 思路
This problem's meaning is that the winner is the lowest sum places of the two round.And now you konw your two places.Please tell me the highest place and the lowest place.
in fact,要求最高名次,就先检查1+n是不是比sum=x+y大,若比sum大的话,就可以剩下的对称这组合成1+n直接第一名;若不行,就先保守地把最小的1 1组合拿走,接下来检查2+n。。。直到发现k+n大于x+y,就又可以对称选了,名次的规律就像代码那样ans=min(n,sum-n+1);
To get the lowest place,求最低名次就是想办法凑成x+y,用最苟的方法消灭大数(求最高名次本质是用最小的代价消灭最小数),这个也一样,遇到x+y小于n+1的,就为了以后的考虑,直接消灭n+n,破罐子破摔,然后规律就这样的if(sum>n) return n; else return sum-1;
1 #include<iostream> 2 #define rep(i,a,b) for(ll i=a;i<=b;++i) 3 #define per(i,a,b) for(ll i=a;i>=b;--i) 4 #define fi first 5 #define se second 6 #define pb push_back 7 #define mp make_pair 8 #define all(x) x.begin(),x.end() 9 typedef long long ll; 10 typedef std::pair<ll,ll> PII; 11 using namespace std; 12 13 int BestPlace(int n,int x,int y){ 14 int sum=x+y; 15 if(sum<n+1) return 1; 16 else return min(n,sum-n+1); 17 } 18 int WorstPlace(int n,int x,int y){ 19 int sum=x+y; 20 if(sum>n) return n; 21 else return sum-1; 22 } 23 int main() 24 { 25 int t; 26 cin>>t; 27 while(t--){ 28 int n,x,y; 29 cin>>n>>x>>y; 30 cout<<BestPlace(n,x,y)<<' '<<WorstPlace(n,x,y)<<endl; 31 } 32 return 0; 33 }

浙公网安备 33010602011771号