首页 > 代码库 > ACdream原创群赛(18)のAK's dream

ACdream原创群赛(18)のAK's dream

A -KIDx‘s Pagination

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

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

There are multiple cases.
Ease case contains three integers n, cur, d.
1 ≤ n ≤ 100.
1 ≤ cur ≤ n.
0 ≤ d ≤ n.

Output

For each test case, output one line containing "Case #x: " followed by the result of pagination.

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 <iostream>
#include <cstdio>
 
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

Time Limit: 6000/3000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

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.

Swords

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
AC代码:

 

/*
* this code is made by eagle
* Problem: 1199
* Verdict: Accepted
* Submission Date: 2014-09-06 20:57:36
* Time: 532MS
* Memory: 2456KB
*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
 
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++

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

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
AC代码:

/*
* this code is made by eagle
* Problem: 1202
* Verdict: Accepted
* Submission Date: 2014-09-06 20:36:06
* Time: 0MS
* Memory: 1676KB
*/
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
 
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

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

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 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 <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
 
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;
}

未完待续!!!!


ACdream原创群赛(18)のAK's dream