First question
Simple simulation, the S split into a binary form, and then statistics how many one, will be ans/n*m simplification.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <ctime>7#include <algorithm>8 using namespacestd;9 Long LongN,m,s,ans;TenInlineLong LongRead () One { A Long Longx=0, f=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} - while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} the returnx*F; - } - Long LonggcdLong LongALong Longb) {returnb==0? A:GCD (b,a%b);} - intMain () + { -Freopen ("huajitree.in","R", stdin); +Freopen ("Huajitree.out","W", stdout); AN=read (); M=read (); s=read (); at while(s) {if(s%2==1) ans++; S/=2;} - Long LongR=GCD (ans,n*m); - if(!ans) printf ("0\n"); - Elseprintf"%i64d/%i64d\n", ans/r,m*n/R); - return 0; -}View Code
Second question
Unable to spit the trough greedy water, see positive solution dynamic planning.
Using SUMV and SUMH respectively to maintain the prefix of V and H and, f[i] to indicate the minimum cost of putting the first I item into the backpack, it is easy to write the state transition equation: f[i]=min{f[i],f[j]+sumh[i]* (sumv[i]-sumv[j])}
The time complexity of O (n^2) can be over 60 points, then slope optimization is required.
Assuming that the transfer from K to I is better than J, then there is f[k]+sumh[i]*sumv[i]-sumh[i]*sumv[k]<f[j]+sumh[i]*sumv[i]-sumh[i]*sumv[j]
Simplification (F[k]-f[j])/(Sumv[k]-sumv[j]) <sumh[i]
This is the slope expression, and then the convex hull can be maintained.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <ctime>7#include <algorithm>8 #defineMAXN 10000109 using namespacestd;Ten Long LongN,F[MAXN],V[MAXN],H[MAXN],SUMV[MAXN],SUMH[MAXN],Q[MAXN]; OneInlineLong LongRead () A { - Long Longx=0, f=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} the while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} - returnx*F; - } - Long LongSlopLong LongALong Longb) {return(F[a]-f[b])/(sumv[a]-sumv[b]);} + intMain () - { +Freopen ("pack.in","R", stdin); AFreopen ("Pack.out","W", stdout); atn=read (); - for(intI=1; i<=n;i++) - { -v[i]=read (); -h[i]=read (); -sumv[i]=v[i]+sumv[i-1]; insumh[i]=h[i]+sumh[i-1]; -f[i]=sumv[i]*Sumh[i]; to } +f[1]=v[1]*h[1]; - Long LongL=0, r=0; the for(intI=1; i<=n;i++) * { $ while(L<r&&slop (q[l],q[l+1]) <sumh[i]) l++;Panax Notoginseng Long Longt=Q[l]; -f[i]=f[t]+sumh[i]* (sumv[i]-sumv[t]); the while(L<r&&slop (q[r-1],q[r]) >slop (q[r],i)) r--; +q[++r]=i; A } theprintf"%i64d\n", F[n]); + return 0; -}View Code
Third question
Segment Tree Maintenance diagram connectivity, when the exam did not think of, wrote a violent, and then hung up.
0904 Problem Solving Report