Problem Description
One Day, KIDx developed a beautiful pagination for ACdream. Now, KIDx wants you to make another one.
The are n pages in total.
The current page is cur.
The max distance to current page you can display is d.
Here are some rules:
- The cur page button is disabled.
- If cur page is the first page, the button "<<" should be disabled.
- If cur page is the last page, the button ">>" should be disabled.
- If the button "x" is disabled, print "[x]"; else print "(x)".
- You should not display the "..." button when there is no hidden page.
You can assume that the button "..." is always disabled.
Input
Ease case contains three integers n, cur, d.
1 ≤ n ≤ 100.
1 ≤ cur ≤ n.
0 ≤ d ≤ n.
Output
Sample Input
10 5 2 10 1 2
Sample Output
Case #1: (<<)[...](3)(4)[5](6)(7)[...](>>) Case #2: [<<][1](2)(3)[...](>>)
Hint
Case 1:
Case 2:
AC代码:
/*
* this code is made by eagle
* Problem: 1196
* Verdict: Accepted
* Submission Date: 2014-09-06 20:08:40
* Time: 0MS
* Memory: 1676KB
*/
#include
#include
using namespace std;
int main()
{
int n,cur,d,tp,cnt = 0;
//freopen("in.txt","r",stdin);
while(~scanf("%d %d %d",&n,&cur,&d))
{
printf("Case #%d: ",++cnt);
if(cur != 1) printf("(<<)");
else printf("[<<]");
if(cur - d > 1) printf("[...]");
if(cur - d < 1) tp = 1;
else tp = cur - d;
for(int i = tp; i < cur && i >= 1; i++)
printf("(%d)",i);
printf("[%d]",cur);
for(int i = cur + 1; i <= cur + d && i <= n; i++)
printf("(%d)",i);
if(cur + d < n) printf("[...]");
if(cur != n) printf("(>>)");
else printf("[>>]");
puts("");
}
return 0;
}
D -Heros and Swords
Problem Description
There are n swords of different weights Wi and n heros of power Pi.
Your task is to find out how many ways the heros can carry the swords so that each hero carries exactly one sword.
Here are some rules:
(1) Every sword is carried by one hero and a hero cannot carry a sword whose weight is larger than his power.
(2) Two ways will be considered different if at least one hero carries a different sword.
Input
The first line of the input gives the number of test cases T(1 ≤ T ≤ 50).
Each case starts with a line containing an integer n (1 ≤ n ≤ 105)denoting the number of heros and swords.
The next line contains n space separated distinct integers denoting the weight of swords.
The next line contains n space separated distinct integers denoting the power for the heros.
The weights and the powers lie in the range [1, 109].
Output
For each case, output one line containing "Case #x: " followed by the number of ways those heros can carry the swords.
This number can be very big. So print the result modulo 1000 000 007.
Sample Input
3 5 1 2 3 4 5 1 2 3 4 5 2 1 3 2 2 3 2 3 4 6 3 5
Sample Output
Case #1: 1 Case #2: 0 Case #3: 4
/*
* this code is made by eagle
* Problem: 1199
* Verdict: Accepted
* Submission Date: 2014-09-06 20:57:36
* Time: 532MS
* Memory: 2456KB
*/
#include
#include
#include
#include
#include
using namespace std;
const int M = 1e5 + 5;
const int mod = 1000000007;
int a[M],b[M];
int main()
{
// freopen("in.txt","r",stdin);
int T,n,cnt = 0;
scanf("%d",&T);
while(T--)
{
printf("Case #%d: ",++cnt);
long long ans = 1;
int vis = 0;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d",a + i);
for(int i = 0; i < n; i++)
scanf("%d",b + i);
sort(b, b + n);
sort(a, a + n);
for(int i = n - 1; i >= 0; i--)
{
int tp = lower_bound(b, b + n,a[i]) - b;
if(tp == n)
{
vis = 1;
break;
}
else
{
ans = ( ans * (i + 1 - tp) ) % mod;
}
}
if(vis) puts("0");
else printf("%lld\n",ans);
}
return 0;
}
G -Integer in C++
Problem Description
KIDx: I like Java much more than C++, because I can use BigInteger in Java. :)
However, KIDx has to use C++ language to do a project...
KIDx can only use three integer types in C++:
1) short occupies 2 bytes and allows you to store numbers from-32768 to 32767
2) int occupies 4 bytes and allows you to store numbers from -2147483648 to 2147483647
3) long long occupies 8 bytes and allows you to store numbers from-9223372036854775808 to 9223372036854775807
For all the types given above the boundary values are included in the value range.
From this list, KIDx wants you to choose the smallest type that can store a positive integern.
Input
There are multiple cases.
Each case contains a positive integer n.
It consists of at least one digit and at most 30 digits.
In addition, it doesn't contain any leading zeros.
Output
For each line, print the first type from the list "short, int, long long", that can store the natural numbern.
If no one can store the number, just print "It is too big!".
Sample Input
102 50000
Sample Output
short int
/*
* this code is made by eagle
* Problem: 1202
* Verdict: Accepted
* Submission Date: 2014-09-06 20:36:06
* Time: 0MS
* Memory: 1676KB
*/
#include
#include
#include
#include
using namespace std;
int main()
{
char s[33];
unsigned long long ans,tp;
while(~scanf("%s",s))
{
int len = strlen(s);
if(len > 19) puts("It is too big!");
else
{
ans = 0;
for(int i = 0; s[i]; i++)
ans = ans * 10 + s[i] - '0';
if(ans > 9223372036854775807) puts("It is too big!");
else if(ans > 2147483647) puts("long long");
else if(ans > 32767) puts("int");
else puts("short");
}
}
return 0;
}
I -Integration of Polynomial
Problem Description
Suppose there are a polynomial which has n nonzero terms, please print the integration polynomial of the given polynomial.
The polynomial will be given in the following way, and you should print the result in the same way:
k[1] e[1] k[2] e[2] ... k[n] e[n]
where k[i] and e[i] respectively represent the coefficients and exponents of nonzero terms, and satisfiese[1] < e[2] < ... < e[n].
Note:
- Suppose that the constant term of the integration polynomial is 0.
- If one coefficient of the integration polynomial is an integer, print it directly.
- If one coefficient of the integration polynomial is not an integer, please print it by using fractiona/b which satisfies that a is coprime to b.
Input
There are multiple cases.
For each case, the first line contains one integer n, representing the number of nonzero terms.
The second line contains 2*n integers, representing k[1], e[1], k[2], e[2], ..., k[n], e[n]。
1 ≤ n ≤ 1000
-1000 ≤ k[i] ≤ 1000, k[i] != 0, 1 ≤ i ≤ n
0 ≤ e[i] ≤ 1000, 1 ≤ i ≤ n
Output
Print the integration polynomial in one line with the same format as the input.
Notice that no extra space is allowed at the end of each line.
Sample Input
3 1 0 3 2 2 4
Sample Output
1 1 1 3 2/5 5
Hint
f(x) = 1 + 3x2 + 2x4
After integrating we get: ∫f(x)dx = x + x3 + (2/5)x5
AC代码:
/*
* this code is made by eagle
* Problem: 1204
* Verdict: Accepted
* Submission Date: 2014-09-06 21:24:26
* Time: 16MS
* Memory: 1684KB
*/
#include
#include
#include
#include
#include
#include
using namespace std;
const int M = 1100;
const int mod = 1000000007;
int a[M],b[M];
int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i = 0; i < n; i++)
{
scanf("%d %d",a + i,b + i);
b[i]++;
}
for(int i = 0; i < n; i++)
{
int tp = a[i] / b[i] * b[i];
if(tp == a[i]) printf("%d %d",a[i] / b[i],b[i]);
else
{
tp = gcd(abs(a[i]),abs(b[i]));
printf("%d/%d %d",a[i] / tp,b[i] / tp, b[i]);
}
if(i == n - 1) puts("");
else printf(" ");
}
}
return 0;
}
Xor
Problem Description
For given multisets A and B, find minimum non-negative x which A⊕x=B.
Note that for A={a1,a2,…,an}, A⊕x={a1⊕x,a2⊕x,…,an⊕x}. ⊕ stands for exclusive-or.
Input
The first line contains a integer n, which denotes the size of set A (also for B).
The second line contains n integers a1,a2,…,an, which denote the set A.
The thrid line contains n integers b1,b2,…,bn, which denote the set B.
(1≤n≤105, n is odd, 0≤ai,bi<230)
Output
The only integer denotes the minimum x. Print −1 if no such x exists.
Sample Input
3 0 1 3 1 2 3
Sample Output
2
Source
Manager
数论,位进制和异或,首先要知道位为0的异或是不起作用的;
所以可以这样做,统计数的每一位的1的个数,如果不相等,则该位应该为1;
AC代码:
/*
* this code is made by eagle
* Problem: 1023
* Verdict: Accepted
* Submission Date: 2014-09-07 20:08:14
* Time: 624MS
* Memory: 3240KB
*/
#include
#include
#include
using namespace std;
typedef long long ll;
const int M = 1e5 + 5;
ll a[M],b[M];
int ua[32],ub[32],n;
void num(ll *a, int *c)
{
for(int i = 0; i < 30; i++)
for(int j = 0; j < n; j++)
c[i] += ( a[j] & (1 << i) ) ? 1 : 0;
}
int main()
{
ll x,m;
scanf("%d",&n);
for(int i = 0; i < n; i++)
cin>>a[i];
for(int i = 0; i < n; i++)
cin>>b[i];
num(a,ua);
num(b,ub);
x = 0;
m = 1;
for(int i = 0; i < 30; i++)
{
if(ua[i] != ub[i]) x += m;
m <<= 1;
}
for(int i = 0; i < n; i++)
a[i] ^= x;
sort(a, a + n);
sort(b, b + n);
for(int i = 0; i < n; i++)
{
if(a[i] != b[i])
{
puts("-1");
return 0;
}
}
cout<