Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 4915
I am so old that my mind will not be moved, but even if I have searched question a, I still haven't figured out my way of thinking.
Three points:
1. segma (A [I]-B [I]) must be an even number, because each operation is equivalent to minus 2 * Delta
2. A [I]> = B [I] The question is clearly stated and can only be subtracted. Therefore, this must satisfy
I thought of the first two points, but I could give a counterexample. Then my teammate a fell.
3. Max (A [I]-B [I]) * 2 <= segma (A [I]-B [I]). Otherwise, the maximum value will definitely not be deleted.
But I still haven't summed up my thinking methods. I have been doing this all the time. I have enumerated the examples from an early age, searched for methods, and then promoted them to a large one, but it seems that I can't do it this time.
You may need to summarize the rules from the counterexamples. If you want to solve the problem, you should be right.
#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <iostream>#include <iomanip>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;#define ls(rt) rt*2#define rs(rt) rt*2+1#define ll long long#define ull unsigned long long#define rep(i,s,e) for(int i=s;i<e;i++)#define repe(i,s,e) for(int i=s;i<=e;i++)#define CL(a,b) memset(a,b,sizeof(a))#define IN(s) freopen(s,"r",stdin)#define OUT(s) freopen(s,"w",stdout)const ll ll_INF = ((ull)(-1))>>1;const double EPS = 1e-8;const int INF = 100000000;const int MAXN = 10000+100;ll a[MAXN],b[MAXN];ll vis[MAXN];int n;int main(){ while(~scanf("%d",&n)) { CL(vis,0); int flag=1; ll mmax=0,ret=0; for(int i=0;i<n;i++) { scanf("%lld%lld",&a[i],&b[i]); if(a[i]<b[i])flag=0; if(a[i]>=b[i])vis[i]=a[i]-b[i]; mmax=max(vis[i],mmax); ret+=vis[i]; } if(flag==0 || 2*mmax >ret || ret%2) printf("NO\n"); else printf("YES\n"); } return 0;}
Zoj 3672 thinking questions