1. 程式人生 > >"虹軟杯" 中國大學生程式設計競賽 (杭州賽區)-網路賽水題題解

"虹軟杯" 中國大學生程式設計競賽 (杭州賽區)-網路賽水題題解

本次網路賽四大水題:

HDU5832 A water problem

Problem Description
Two planets named Haha and Xixi in the universe and they were created with the universe beginning.

There is 73 days in Xixi a year and 137 days in Haha a year.

Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.

Input
There are several test cases(about 5 huge test cases).

For each test, we have a line with an only integer N(0≤N), the length of N is up to 10000000.

Output
For the i-th test case, output Case #i: , then output “YES” or “NO” for the answer.

Sample Input
10001
0
333

Sample Output
Case #1: YES
Case #2: YES
Case #3: NO

大數取餘模板題

HDU5833
Zhu and 772002

Problem Description
Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem.

But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.

There are n numbers a1,a2,..

.,an. The value of the prime factors of each number does not exceed 2000, you can choose at least one number and multiply them, then you can get a number b.

How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.

Input
First line is a positive integer T , represents there are T test cases.

For each test case:

First line includes a number n(1n300),next line there are n numbers a1,a2,...,an,(1ai1018).

Output
For the i-th test case , first output Case #i: in a single line.

Then output the answer of i-th test case modulo by 1000000007.

Sample Input
2
3
3 3 4
3
2 2 2

Sample Output
Case #1:
3
Case #2:
3

詳細見 UVa11542,注意結果會超long long,需要迴圈取餘。

HDU5842 Lweb and String

Problem Description
Lweb has a string S.

Oneday, he decided to transform this string to a new sequence.

You need help him determine this transformation to get a sequence which has the longest LIS(Strictly Increasing).

You need transform every letter in this string to a new number.

A is the set of letters of S, B is the set of natural numbers.

Every injection f:AB can be treat as an legal transformation.

For example, a String “aabc”, A={a,b,c}, and you can transform it to “1 1 2 3”, and the LIS of the new sequence is 3.

Now help Lweb, find the longest LIS which you can obtain from S.

Input
The first line of the input contains the only integer T,(1T20).

Then T lines follow, the i-th line contains a string S only containing the lowercase letters, the length of S will not exceed 105.

Output
For each test case, output a single line “Case #x: y”, where x is the case number, starting from 1. And y is the answer.

Sample Input
2
aabcc
acdeaa

Sample Output
Case #1: 3
Case #2: 4

只需要記一下不相同的字母有多少個即可

Danganronpa

Problem Description
Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gifts to the monitor, Chiaki Nanami. Due to the strange design of the school, the students’ desks are in a row. Chiaki Nanami wants to arrange gifts like this:

  1. Each table will be prepared for a mysterious gift and an ordinary gift.

  2. In order to reflect the Chisa Yukizome’s generosity, the kinds of the ordinary gift on the adjacent table must be different.

  3. There are no limits for the mysterious gift.

  4. The gift must be placed continuously.

She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren’t you?

Input
The first line of input contains an integer T(T≤10) indicating the number of test cases.

Each case contains one integer n. The next line contains n (1≤n≤10) numbers: a1,a2,…,an, (1≤ai≤100000).

Output
For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the answer of Chiaki Nanami’s question.

Sample Input
1
2
3 2

Sample Output
Case #1: 2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
const int maxn = 100007;
int kase, T = 0, a[15], n, ans;
int main() {
    scanf("%d", &kase);
    while(kase--) {
        int ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int cnt = a[0];
        for(int i = 1; i < n; ++i) {
            ans += min(cnt, a[i])*2;
            cnt = abs(cnt-a[i]);
        }
        if(cnt>0) ans++,cnt--;
        if(ans>=cnt) ans = (ans+cnt)/2;
        printf("Case #%d: %d\n", ++T, ans);
    }
}