Bestcoder
Tom and paper
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.
Sample Input
3
2
7
12
Sample Output
6
16
14
- 暴力枚举啊,怎么刚开赛那会儿就想不通了?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29int main()
{
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);
}
return 0;
}
Tom and permutation
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
75Hint
The input may be very big, we might as well optimize input.
1 |
|
Tom and matrix
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.
Sample Input
0 0 1 1 7
1 1 2 2 13
1 0 2 1 2
Sample Output
3
4
1
1 |