typedef long long LL; typedef unsigned long long ULL; const int maxn=1010; const int inf=0x7fffffff; const double eps=1e-3;
const int m1=0x00fc0000; const int m2=0x0003f000; const int m3=0x00000fc0; const int m4=0x0000003f;
char str[maxn];
char chs(char ch) { if (ch>=0&&ch<26) return ch+’A’; else if (ch>=26&&ch<52) return ch-26+’a’; else if (ch>=52&&ch<62) return ch-52+’0’; else if (ch==62) return ‘+’; else if (ch==63) return ‘/‘; }
void solve(char str[maxn]) { char s[maxn]={‘\0’}; int len=strlen(str); int tmp=0; int pos=0; for(int i=0;i<len;i++) { tmp<<=8;tmp+=int(str[i]); if (!((i+1)%3)) { s[pos++]=chs((tmp&m1)>>18); s[pos++]=chs(((tmp&m2)>>12)); s[pos++]=chs(((tmp&m3)>>6)); s[pos++]=chs((tmp&m4)); tmp=0; } } if (len%3) { tmp<<=(3-len%3)*8; if ((tmp&m1)>0) s[pos++]=chs((tmp&m1)>>18); if ((tmp&m2)>0) s[pos++]=chs(((tmp&m2)>>12)); if ((tmp&m3)>0) s[pos++]=chs(((tmp&m3)>>6)); if ((tmp&m4)>0) s[pos++]=chs((tmp&m4)); } int sum=4-strlen(s)%4; char *t=s+strlen(s); if (sum<4) for(int j=1;j<=sum;j++) *t++=’=’; *t=’\0’; strcpy(str,s); }
int main() { int T; scanf(“%d”,&T); while(T–) { int k; scanf(“%d%s”,&k,str); for(int i=1;i<=k;i++) solve(str); printf(“%s\n”,str); } return 0; } [/cpp]
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
Given a string S and two integers L and M, we consider a substring of S as “recoverable” if and only if (i) It is of length M*L; (ii) It can be constructed by concatenating M “diversified” substrings of S, where each of these substrings has length L; two strings are considered as “diversified” if they don’t have the same character for every position.
Two substrings of S are considered as “different” if they are cut from different part of S. For example, string “aa” has 3 different substrings “aa”, “a” and “a”.
Your task is to calculate the number of different “recoverable” substrings of S.
Input
The input contains multiple test cases, proceeding to the End of File.
The first line of each test case has two space-separated integers M and L.
The second ine of each test case has a string S, which consists of only lowercase letters.
The length of S is not larger than 10^5, and 1 ≤ M * L ≤ the length of S.
Output
For each test case, output the answer in a single line.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Problem Description
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more. The merchants were the most typical, each of them only sold exactly one item, the price was Pi, but they would refuse to make a trade with you if your money were less than Qi, and iSea evaluated every item a value Vi. If he had M units of money, what’s the maximum value iSea could get?
Input
There are several test cases in the input.
Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money. Then N lines follow, each line contains three numbers Pi, Qi and Vi (1 ≤ Pi ≤ Qi ≤ 100, 1 ≤ Vi ≤ 1000), their meaning is in the description.
The input terminates by end of file marker.
Output
For each test case, output one integer, indicating maximum value iSea could get.
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depending on the days he spend on it.How to arrange the M days for the N courses to maximize the profit?
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers N and M, N is the number of courses, M is the days ACboy has. Next follow a matrix A[i][j], (1<=i<=N<=100,1<=j<=M<=100).A[i][j] indicates if ACboy spend j days on ith course he will get profit of value A[i][j]. N = 0 and M = 0 ends the input.
Output
For each data set, your program should output a line which contains the number of the max profit ACboy will gain.
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)
Problem Description FJ is going to do some shopping, and before that, he needs some boxes to carry the different kinds of stuff he is going to buy. Each box is assigned to carry some specific kinds of stuff (that is to say, if he is going to buy one of these stuff, he has to buy the box beforehand). Each kind of stuff has its own value. Now FJ only has an amount of W dollars for shopping, he intends to get the highest value with the money.
Input
The first line will contain two integers, n (the number of boxes 1 <= n <= 50), w (the amount of money FJ has, 1 <= w <= 100000) Then n lines follow. Each line contains the following number pi (the price of the ith box 1<=pi<=1000), mi (1<=mi<=10 the number goods ith box can carry), and mi pairs of numbers, the price cj (1<=cj<=100), the value vj(1<=vj<=1000000)
Output
For each test case, output the maximum value FJ can get
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
Homelesser likes playing Gold miners in class. He has to pay much attention to the teacher to avoid being noticed. So he always lose the game. After losing many times, he wants your help.
To make it easy, the gold becomes a point (with the area of 0). You are given each gold’s position, the time spent to get this gold, and the value of this gold. Maybe some pieces of gold are co-line, you can only get these pieces in order. You can assume it can turn to any direction immediately. Please help Homelesser get the maximum value.
Input
There are multiple cases. In each case, the first line contains two integers N (the number of pieces of gold), T (the total time). (0<N≤200, 0≤T≤40000) In each of the next N lines, there four integers x, y (the position of the gold), t (the time to get this gold), v (the value of this gold). (0≤|x|≤200, 0<y≤200,0<t≤200, 0≤v≤200)
Output
Print the case number and the maximum value for each test case.
intmain() { int n,m,kase=0; while(~scanf("%d%d",&n,&m)) { mp.clear(); for(int i=1;i<=n;i++) { int x,y,t,v; scanf("%d%d%d%d",&x,&y,&t,&v); gold[i]=data(x,y,t,v);
} //puts("--"); sort(gold+1,gold+n+1); int cnt=1; vc[cnt].clear(); for(int i=1;i<=n;i++) { if (vc[cnt].size()) { data tmp=vc[cnt][vc[cnt].size()-1]; gold[i]=data(gold[i].x,gold[i].y,gold[i].t+tmp.t,gold[i].v+tmp.v); } vc[cnt].push_back(gold[i]); if (gold[i]!=gold[i+1]) vc[++cnt].clear(); } CLEAR(f); /*for(int k=1;k<=cnt;k++) { for(int i=0;i<vc[k].size();i++) vc[k][i].prt(); puts("-"); }*/
for(int k=1;k<=cnt;k++) for(int j=m;j>=0;j--) for(int i=0;i<vc[k].size();i++) if (j>=vc[k][i].t) f[j]=max(f[j],f[j-vc[k][i].t]+vc[k][i].v);
printf("Case %d: %d\n",++kase,f[m]); } return0; }
Beam Cannon
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaceships is approaching. There is a very large Beam Cannon on the Planet X, and it is very powerful, which can destroy all the spaceships in its attack range in a second. However, it takes a long time to fill the energy of the Beam Cannon after each shot. So, you should make sure each shot can destroy the enemy spaceships as many as possible. To simplify the problem, the Beam Cannon can shot at any area in the space, and the attack area is rectangular. The rectangle parallels to the coordinate axes and cannot rotate. It can only move horizontally or vertically. The enemy spaceship in the space can be considered as a point projected to the attack plane. If the point is in the rectangular attack area of the Beam Cannon(including border), the spaceship will be destroyed.
Input
Input contains multiple test cases. Each test case contains three integers N(1<=N<=10000, the number of enemy spaceships), W(1<=W<=40000, the width of the Beam Cannon’s attack area), H(1<=H<=40000, the height of the Beam Cannon’s attack area) in the first line, and then N lines follow. Each line contains two integers x,y (-20000<=x,y<=20000, the coordinates of an enemy spaceship). A test case starting with a negative integer terminates the input and this test case should not to be processed.
Output
Output the maximum number of enemy spaceships the Beam Cannon can destroy in a single shot for each case.
Sample Input
2 3 4 0 1 1 0 3 1 1 -1 0 0 1 1 0 -1
Sample Output
2 2
Source
2014上海全国邀请赛——题目重现(感谢上海大学提供题目)
FATE
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.
Input
In the first line, there is an integer T indicates the number of test cases. In the next T lines, there is only one integer n in every line, indicates the area of paper. $ T\leq 10,n\leq {10}^{9} $
Output
For each case, output a integer, indicates the answer.
intmain() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); int i, a, b; if (n > 1) for (i = (int)sqrt(n); i > 0; i++) { a = i; b = n / a; if (a * b == n) { break; } } else { a = 1; b = n / a; }; //cout<<a<<' '<<b<<endl; printf("%d\n", 2 * a + 2 * b); } return0; }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Tom has learned how to calculate the number of inversions in a permutation of n distinct objects by coding, his teacher gives him a problem: Give you a permutation of n distinct integer from 1 to n, there are many permutations of 1-n is smaller than the given permutation on dictionary order, and for each of them, you can calculate the number of inversions by coding. You need to find out sum total of them. Tom doesn’t know how to do, he wants you to help him. Because the number may be very large, output the answer to the problem modulo $ {10}^{9}+{7} $ .
Input
Multi test cases(about 20). For each case, the first line contains a positive integer n, the second line contains n integers, it’s a permutation of 1-n. $ n\leq 100 $
Output
For each case, print one line, the answer to the problem modulo $ {10}^{9}+7 $ .
Sample Input
3 2 1 3 5 2 1 4 3 5
Sample Output
1 75
Hint
The input may be very big, we might as well optimize input.
for(int k = 1 ; k <= n ; k++){ for(int i = 1 ; i < k ; i++){ for(int j = k ; j <= n ; j++){ if(a[i] > a[j]) eb[k]++ ; } } }
LL sum = 0 ; for(int i = 1 ; i <= n ; i++){
sum += (eb[i] + N[i-1])*(les[i] * fac[n-i] )% mod ; sum %= mod ; sum += fac[n-i] * (les[i] * (les[i]-1) / 2) % mod ; sum %= mod ; sum += dp[n-i] * les[i] % mod ; sum %= mod ; }
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Tom was on the way home from school. He saw a matrix in the sky. He found that if we numbered rows and columns of the matrix from 0, then, $ {a} _ {i,j}={C} _ {i}^{j}$ if i < j, $ {a}_{i,j}=0$ Tom suddenly had an idea. He wanted to know the sum of the numbers in some rectangles. Tom needed to go home quickly, so he wouldn’t solve this problem by himself. Now he wants you to help him. Because the number may be very large, output the answer to the problem modulo a prime p.
Input
Multi test cases(about 8). Each case occupies only one line, contains five integers, $ x_{1}、y_{1}、x_{2}、y_{2}、p. x_{1}\leq x_{2}\leq {10}^{5},y_{1}\leq y_{2}\leq {10}^{5},2\leq p\leq {10}^{9}$ .
Output
For each case, print one line, the answer to the problem modulo p.
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)
Problem Description
Yuanfang is puzzled with the question below: There are n integers, a1, a2, …, an. The initial values of them are 0. There are four kinds of operations. Operation 1: Add c to each number between ax and ay inclusive. In other words, do transformation ak<—ak+c, k = x,x+1,…,y. Operation 2: Multiply c to each number between ax and ay inclusive. In other words, do transformation ak<—ak×c, k = x,x+1,…,y. Operation 3: Change the numbers between ax and ay to c, inclusive. In other words, do transformation ak<—c, k = x,x+1,…,y. Operation 4: Get the sum of p power among the numbers between ax and ay inclusive. In other words, get the result of axp+ax+1p+…+ay p. Yuanfang has no idea of how to do it. So he wants to ask you to help him.
Input
There are no more than 10 test cases. For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000. Each the following m lines contains an operation. Operation 1 to 3 is in this format: “1 x y c” or “2 x y c” or “3 x y c”. Operation 4 is in this format: “4 x y p”. (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3) The input ends with 0 0.
Output
For each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.