T1 cuisine
Description
Food is very tasty dish of meaning, food is the most important to choose a good raw material.
There are N kinds of ingredients, each of both acidity and S B Bitterness two attributes, when selecting a variety of materials, a total acidity of the acidity of the product of each ingredient, the total degree of bitterness Bitterness of each ingredient with.
As you know, neither food nor bitter acid, as a raw material to ensure that the selected total acidity and total pain of the minimum absolute difference.
Because food is not only water, so you must select at least one meal.
Input
Input of the first row contains an integer N (1 <= N <= 10), indicates the number of kinds of raw materials.
Next N lines contains two integers separated by a space, respectively, of the acidity and bitter.
If the input data to ensure that all the raw materials are selected, total acidity and total pain of no more than 10 ^ 9.
Output
Minimum difference between the total acidity and total output of bitter.
Examination room ideas / positive solution
what? 1 <= N <= 10? Dfs! How violence, how ever (no brain)!
Code
#include<stdio.h> #include<algorithm> using namespace std; int n,ans; int book[15]; struct thm { int a; int b; }sz[15]; void Work(int nowa,int nowb) { ans=min(abs(nowa-nowb),ans); for(int i=1;i<=n;i++) { if(book[i]) continue; book[i]=1; Work(nowa*sz[i].a,nowb+sz[i].b); book[i]=0; } } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&sz[i].a,&sz[i].b); ans=2e9; for(int i=1;i<=n;i++) { book[i]=1; Work(sz[i].a,sz[i].b); book[i]=0; } printf("%d",ans); return 0; }
T2 fetch game
Description
N positive integers circle, rules are as follows:
• two players take turns fetching;
• the beginning just get a player can take any number x;
• the beginning of the current player can only take x from the second step (the player just take a number) left and right sides of adjacent numbers;
• take complete until all the numbers, the game is over;
• get more odd number of wins.
Bob in order to show generosity, let Alice first take, but he forgot himself and Alice are very smart people, Alice now ask you to help him calculate how many emulated the first step in making the final victory.
Input
Output
Sample Input
Input 1: 3 3 1. 5 Input 2: . 4 1 2 3. 4 input 3: . 8 . 4. 9 10. 8. 5 2 1. 7
Sample Output
Output 1: 3 Output 2: 2 Output 3: 5
Examination room ideas / positive solution
emmmm This is obviously a question of range DP (I think that is the most difficult question 4.), I spent a half-hour exam to push this problem, and finally launch, but there is some small mistakes in the handling of the border, only 50 (tears ran).
Provided f1 [i] [j] denotes the current length i, the odd and the position obtained when the first element of j and the upper hand is optimal.
f2 [i] [j] represents the length of the current i, and the odd position of the first element when j is obtained when the optimal flip.
So we is not difficult to draw: If f2 [i-1] [j + 1] + sz [j]% 2> f2 [i-1] [j] + sz [i + j-1]% 2, then f1 [i] [j] = f2 [i-1] [j + 1] + sz [j]% 2, f2 = f1 [i-1] [j + 1], otherwise, f1 [i] [j] = f2 [i-1] [j] + sz [i + j-1]% 2, f2 [i] [j] = f1 [i-1] [j]. (Now the upper hand, will be carried round the access number for the remaining flip-1 i, but now the upper hand FLAC Similarly i-1 for the remaining number.)
so, the core code is:
if((f2[i-1][j+1]+sz[j]%2>f2[i-1][j]+sz[i+j-1]%2) || (f2[i-1][j+1]+sz[j]%2==f2[i-1][j]+sz[i+j-1]%2 && f1[i-1][j+1]<f1[i-1][j])) f1[i][j]=f2[i-1][j+1]+sz[j]%2,f2[i][j]=f1[i-1][j+1]; else f1[i][j]=f2[i-1][j]+sz[i+j-1]%2,f2[i][j]=f1[i-1][j];
(Remember the process boundary)
Code
#include <stdio.h> #include <algorithm> the using namespace STD; int n-, L, R & lt, ANS; int SZ [ 110 ]; int F1 [ 110 ] [ 110 ]; / * F1 [I] [J]: when only the i-th element, and the first element position j, just get optimal value * / int F2 [ 110 ] [ 110 ]; / * F2 [i] [J]: when only the i-th element, and the first element position to an optimal value j, FLAC * / int main () { int a, B; Scanf ( " % D " , & n-); for ( int I = . 1;i<=n;i++) scanf("%d",&sz[i]),sz[i+n]=sz[i]; for(int i=1;i<=2*n;i++) f1[1][i]=sz[i]%2; for(int i=2;i<n;i++) for(int j=1;j<=n;j++) { a=j+1>n ? (j+1)%n : j+1; b=i+j-1>n ? (i+j-1)%n : i+j-1; if((f2[i-1][a]+sz[j]%2>f2[i-1][j]+sz[b]%2) || (f2[i-1][a]+sz[j]%2==f2[i-1][j]+sz[b]%2 && f1[i-1][a]<f1[i-1][j])) f1[i][j]=f2[i-1][a]+sz[j]%2,f2[i][j]=f1[i-1][a]; else f1[i][j]=f2[i-1][j]+sz[b]%2,f2[i][j]=f1[i-1] [J]; } for ( int I = . 1 ; I <= n-; I ++ ) { A = I + . 1 > n-(I +? . 1 )% n-: I + . 1 ; // bloggers is here forget sentence boundaries, cautionary IF (F2 [N- . 1 ] [A] + SZ [I]% 2 > F1 [N- . 1 ] [A]) ANS ++ ; } the printf ( " % D " , ANS); return 0 ; }
T3 delete
Description
Alice now want to delete several columns so that each row after row of identical sequence finished, the program requires a minimum of computing how many columns to delete.
Input
The next three lines each line contains N integers, each a number between 1 to N, the number of the first row and different from each other.
Output
Sample Input
Input 1: . 7 . 5. 4. 3 2 1. 6. 7 . 5. 5 1 1. 3. 4. 7 . 3. 7 1. 4. 5. 6 2 Input 2: . 9 1. 3. 5. 9. 8. 6 2. 4. 7 2 1. 5. 6. 4. 9. 3. 4. 7 . 3. 5 1 986287
Sample Output
Output 1: 4 Output 2: 2
Hint
Example 1, Alice needs to delete four of 2,4,6,7, and each row is drained sequence 1,3,5.
[Data] range
of 40% of the data N <= 100
70% of the data N <= 10000
Examination room ideas / positive solution
Water problem, simulated violence
Code
#include<cstdio> #include<algorithm> using namespace std; int n,kg,ans,book[100010]; int a[100010],b[100010],c[100010]; int cb[100010],cc[100010]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]),cb[b[i]]++; for(int i=1;i<=n;i++) scanf("%d",&c[i]),cc[c[i]]++; while(kg==0) { kg=1; for(int i=1;i<=n;i++) { if(book[i]==0 && (cb[a[i]]<=0 || cc[a[i]]<=0)) { kg=0; ans++; book[i]=1; cb[b[i]]--; cc[c[i]]--; } } } printf("%d",ans); return 0; }
T4 interval
Description
Program calculated maximum length sequence.
Input
Next N lines of two integers A and B depict a section (1 <= A <= B <= 1000000).
Output
Sample Input
Input 1: 3 3. 4 2. 5 1. 6 Input 2: . 5 10 30 20 is 40 30 50 10 60 30 40 Input 3: . 6 1. 4 1. 5 1. 6 1. 7 2. 5 3. 5
Sample Output
Output 1: 4 Output 2: 2
Hint
Example 3 can be found in sequence interval length is 5: [1,7], [1,6], [1,5], [2,5], [3,5]
Examination room ideas
No time to play, emmmmm .....
Clarification: there is no clear title, obviously it is to find a few covered range. So obvious as long as the left point range to do it again sort, then it becomes the subject does not rise up to demand the sequence.
Code
#include<stdio.h> #include<algorithm> using namespace std; int n,Len,a; int s[100010]; struct thm { int l; int r; }sz[100010]; bool cmp(thm a,thm b) { if(a.l==b.l) return a.r>b.r; return a.l<b.l; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&sz[i].l,&sz[i].r); sort(sz+1,sz+1+n,cmp); Len=1; for(int i=1;i<=n;i++) { if(s[Len]<=-sz[i].r) s[++Len]=-sz[i].r; else { a=upper_bound(s+1,s+1+n,-sz[i].r)-s; s[a]= -sz[i].r; } } printf("%d",Len); return 0; }
to sum up
Today partial simple topic, but did not test well, the interval DP equation push for too long, it seems not enough skilled, much brush title.