"Link"; Click here~~
"A question Nth largest Value"PKU 3781 http://poj.org/problem?id=3781
"Main topic" Input 10 number, output the third largest number
"Question B." Equal Sum Partitions "PKU 3782 http://poj.org/problem?id=3782
"The main idea" gives you an integer sequence, a sequence of elements m (m <= 10000), which defines an equal sum partition. Satisfies that the sequence can be divided into several intervals, and equal to each interval
"Problem-solving ideas" The pit point: Looking backward, if found with the previously found interval and equal interval, continue to search until the end of the sequence, the sum of the output interval, otherwise in the subsequent sequence can not be found, directly output the sum of all the current number! (That is, not a monotone sequence)
Understand this, the problem can be directly simulated, data water ~ ~
Code:
/*author:hrw*/#include <bits/stdc++.h>using namespace std;int a[10010];int solve (int n) { int sum=0; for (int i=0; i<n; i++) { sum+=a[i]; int s2=0; for (int j=1+i; j<n; J + +) { s2+=a[j]; if (s2>sum) break; if (s2==sum) { s2=0; if (j==n-1) return sum;}} } return sum;} int main () { int t,m,k,n; cin>>t; while (t--) { cin>>k>>n; for (int i=0; i<n; i++) cin>>a[i]; int ans=solve (n); printf ("%d%d\n", K,ans); } return 0;}
"C.balls" PKU 3783 http://poj.org/problem?id=3783
"The main topic"givenB (b <=)a ball of the same, fromm (M <=)One floor above the other.Kso that the ball is thrown below its floor, the ball will not break in the firstKThe layer will break if it is dropped. In the worst case scenario, you need to throw a few times to determine thisK.
"Problem-solving ideas" after the game was found to be a IOI2004 paper, unexpectedly is the road dynamic planning! , did not do it, very classic, the detailed puzzle can refer to the original paper: click here~~
"D.running Median" PKU 3784 http://poj.org/problem?id=3784
"The main topic" : a length of m (M <= 9999) sequence, each time the number of odd digits is read into, computes the median of the preceding entire sequence.
"problem-solving ideas" two points + tree-like array
since the numbers are Int32 range, so we first need to disperse all the numbers to the subscript, enumerate each number read in, the corresponding bit of the number subscript inserted into the tree array, each time you read an odd number, the use of the tree array of the end of the sum of the nature, if you want to find the first K a large number, then a two-part answer, and then query the tree-like array, if the sum is greater than or equal to K , which represents a candidate solution (because it is guaranteed to be greater than or equal to K the number of the smallest, is the first K large number), repeating the two points until the smallest value is found V Meet sum (V) >= K , the complexity of time O (2 *m * log (M))
Simulations used in competitions
#include <bits/stdc++.h>using namespace Std;int main () { //freopen ("1.txt", "R", stdin); int p,n,k; int a[10000]; scanf ("%d", &p); while (p--) { count = 0; scanf ("%d%d", &k,&n); for (int i = 0; i < n; i++) scanf ("%d", &a[i]); printf ("%d%d\n", K, (n + 1)/2); for (int i = 1; I <= n; i = i + 2) { count++; Sort (a,a+i); if (count% 10!=0) printf ("%d", a[(I-1)/2]); else printf ("%d\n", a[(I-1)/2]); } printf ("\ n"); } return 0;}
two points + tree-like array
#include <bits/stdc++.h>using namespace Std;int a[10005],a[10005],p[10005],n;void Add (int i) {while (i<=n) { P[i]+=1; i+= (i& (-i)); }}int sum (int i) {int t=0; while (i) {t+=p[i]; i-= (i& (-i)); } return t;} int find (int k) {int l=1,r=n,res,mid; while (l<=r) {mid= (l+r)/2; if (a[mid]>=k) {r=mid-1; Res=mid; } else l=mid+1; } return res; int main () {int cas,casn,i,j; scanf ("%d", &cas); while (cas--) {scanf ("%d%d", &casn,&n); memset (P,0,sizeof (p)); printf ("%d%d\n", casn,n/2+1); for (i=1;i<=n;i++) {scanf ("%d", &a[i]); A[i]=a[i]; } int tot=n/2+1,cnt=0,pos; Sort (a+1,a+n+1); for (i=1;i<=n;i++) {pos=find (a[i]); Add (POS); if (i&1) {cnt++; int l=1,r=n,mid,res,k=i/2+1; while (l<=r) { Mid= (L+R)/2; if (sum (mid) >=k) {r=mid-1; Res=mid; } else l=mid+1; } printf ("%d", a[res]); if (cnt%10==0) printf ("\ n"); else if (cnt!=tot) printf (""); }} if (tot%10) printf ("\ n"); } return 0;}
"e.the Next permutation" PKU 3785http://poj.org/problem?id=3785
"To the main idea" given a repeatable element permutation a[i], for the next arrangement.
"The idea of solving problems" directly,~~>_< the title function.
Code:
#include <bits/stdc++.h>using namespace Std;int a[10000];int main () { char str[10000]; int n; int m,i,j; cin>>n; while (n--) { scanf ("%d%s", &m,str); int Len=strlen (str); if (Next_permutation (Str,str+len)) printf ("%d%s\n", m,str); else printf ("%d biggest\n", m); } return 0;}
【
f.adjacent Bit Counts"PKU 3786 http://poj.org/problem?id=3786
"To the main idea" for the length of n binary integer, the logarithm of the adjacent two 1 has K Pairs (reusable) number of integers , the topic is very clear.
"Problem-solving ideas": the length of n, adjacent 1 logarithm of the number of K is dp[n][k], where the end of 0 for Dp[n][k][0], with 1 end of dp[n][k][1], then dp[n][k] = dp[n][k][0] + dp[n][k][1];
And there are the following state transfer equations:
1) The binary number of length n-1 is appended with a 0 at the end, the logarithm of adjacent 1 is unchanged, so there are:
Dp[n][k][0] = dp[n-1][k][0] + dp[n-1][k][1];
2) A binary number with a length of n-1 at the end plus a 1, the logarithm of the adjacent 1 depends on whether the n-1 bit is 0 or 1, when the n-1 bit is 1, the adjacent 1 logarithm +1, and when the n-1 bit is 0, the logarithm of the adjacent 1 is unchanged, so there are:
DP[N][K][1] = dp[n-1][k][0] + dp[n-1][k-1][1];
And in the initial state dp[0][0][0] = 1, dp[0][0][1] = 0
Code:
/*AUTHOR:HRWDP three-dimensional array, dp[i][j][k]:n,k, (0,1) n digits, value bit k, end (0,1) state transition equation: dp[i][j][0]+= (dp[i-1][j][0]+dp[i-1][j][1]) ; dp[i][j][1]+= (dp[i-1][j][0]+dp[i-1][j-1][1]); * * #include <bits/stdc++.h>using namespace Std;int dp[1010][1010 ][2];int Solve (int n,int k) { memset (dp,0,sizeof (DP)); Dp[1][0][0]=dp[1][0][1]=1; for (int i=1;i<=n;i++) for (int j=0;j<=k;j++) { dp[i][j][0]+= (dp[i-1][j][0]+dp[i-1][j][1]); dp[i][j][1]+= (dp[i-1][j][0]+dp[i-1][j-1][1]); } return dp[n][k][0]+dp[n][k][1];} int main () { int t,m,n,k; cin>>t; while (t--) { cin>>m>>n>>k; int Ans=solve (n,k); printf ("%d%d\n", M,ans); } return 0;}
"Team Race # Greater New York Regional 2009" Summary of the problem solving