青島網絡賽部分題解

題目鏈接:http://hdu.hustoj.com/showproblem.php?pid=5878

題目:1001

Problem Description
I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.

After the event, we analysed the laws of failed attacks.
It's interesting that the i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.

At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.


Input
The first line of input contains an integer t (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one integer n (1≤n≤109).


Output
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n.


Sample Input
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789


Sample Output
1
12
14
125
1250
12348
123480
1234800
12348000
123480000


大意:找出能夠用2^a3^b5^c7^d表示並且大於等於N的數


這道題可以通過打表來實現,注意這裏面聲明變量數組是long long 型的,而且學到一個新知識就是可以用 lower_bound實現二分查找。


代碼:

<span style="font-size:18px;">#include <cstdio>
#include <cmath>
#include <algorithm>
#include<iostream>
using namespace std;
const int maxn=1e9;
long long f2[32]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824}
,f3[20]={1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489,1162261467}
, f5[14]={1,5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625},
f7[12]={1,7,49,343,2401,16807,117649,823543,5764801,40353607,282475249,1977326743},sum[10000],ans;
int cnt=0;

int main()
{
    for(int i = 0; i < 31; i++)
    {
        for(int j = 0; j < 20; j++)
        {
            for(int k = 0; k< 14; k++)
            {
                for(int t = 0; t <12; t++)
                {
                    ans = f2[i]*f3[j]*f5[k]*f7[t];
                    if(ans <=maxn && ans>0)
                    {
                        sum[cnt++]=ans;
                    }
                }
            }
        }
    }
    sort(sum,sum+cnt);
    int m;
    scanf("%d", &m);
    while(m--)
    {
        int n;
        scanf("%d", &n);
        printf("%d\n", *lower_bound(sum , sum+cnt , n));
    }
    return 0;
}
</span>




題目鏈接:http://hdu.hustoj.com/showproblem.php?pid=5879

題目:

Problem Description
Given an integer n, we only want to know the sum of 1/k2 where k from 1 to n.


Input
There are multiple cases.
For each test case, there is a single line, containing a single positive integer n.
The input file is at most 1M.


Output
The required sum, rounded to the fifth digits after the decimal point.


Sample Input
1
2
4
8
15


Sample Output
1.00000
1.25000
1.42361
1.52742
1.58044

大意:

計算從1到N的平方的倒數和

打表找出規律就可以,但是要注意輸入文件的大小1M,所以n要以字符串形式讀入


代碼:1002

<span style="font-size:18px;">#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e6 + 5;
char str[N];
double sum[N];

void init()
{
    for(int i = 1; i< N; i++)
            sum[i] = sum[i-1] + (double)1/i/i;
}

int main()
{
    init();
    while(scanf("%s", str) != EOF)
    {
        int len = strlen(str);
        if(len >= 7)
            printf("%.5lf\n",sum[1000000]);
        else
        {
            int n=0;
            for(int i = 0; i< len; i++)
                n = n*10 + str[i] - '0';
            printf("%.5lf\n",sum[n]);
        }
    }
    return 0;
}
</span>

題目鏈接:http://hdu.hustoj.com/showproblem.php?pid=5882

題目:

Problem Description
Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper", and "scissors". The game has only three possible outcomes other than a tie: a player who decides to play rock will beat another player who has chosen scissors ("rock crushes scissors") but will lose to one who has played paper ("paper covers rock"); a play of paper will lose to a play of scissors ("scissors cut paper"). If both players choose the same shape, the game is tied and is usually immediately replayed to break the tie.

Recently, there is a upgraded edition of this game: rock-paper-scissors-Spock-lizard, in which there are totally five shapes. The rule is simple: scissors cuts paper; paper covers rock; rock crushes lizard; lizard poisons Spock; Spock smashes scissors; scissors decapitates lizard; lizard eats paper; paper disproves Spock; Spock vaporizes rock; and as it always has, rock crushes scissors.

Both rock-paper-scissors and rock-paper-scissors-Spock-lizard are balanced games. Because there does not exist a strategy which is better than another. In other words, if one chooses shapes randomly, the possibility he or she wins is exactly 50% no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer N, representing the count of shapes in a game. You need to find out if there exist a rule to make this game balanced.


Input
The first line of input contains an integer t, the number of test cases. t test cases follow.
For each test case, there is only one line with an integer N (2≤N≤1000), as described above.

Here is the sample explanation.

In the first case, donate two shapes as A and B. There are only two kind of rules: A defeats B, or B defeats A. Obviously, in both situation, one shapes is better than another. Consequently, this game is not balanced.

In the second case, donate two shapes as A, B and C. If A defeats B, B defeats C, and C defeats A, this game is balanced. This is also the same as rock-paper-scissors.

In the third case, it is easy to set a rule according to that of rock-paper-scissors-Spock-lizard.


Output
For each test cases, output "Balanced" if there exist a rule to make the game balanced, otherwise output "Bad".


Sample Input
3
2
3
5


Sample Output
Bad
Balanced
Balanced


大意:

根據給出的人數,判斷是否可以使比賽平衡


方法:

判斷奇偶就可以


<span style="font-size:18px;">#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int n;
    int t;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        if(n%2 == 0)
            printf("Bad\n");
        else
            printf("Balanced\n");
    }
    return 0;
}
</span>

1006

題目鏈接:http://hdu.hustoj.com/showproblem.php?pid=5883

題目:

Alice is planning her travel route in a beautiful valley. In this valley, there are N lakes, and M rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up a path which go through every river exactly once. In addition, Alice has a specific number (a1,a2,...,an) for each lake. If the path she finds is P0→P1→...→Pt, the lucky number of this trip would be aP0XORaP1XOR...XORaPt. She want to make this number as large as possible. Can you help her?


Input
The first line of input contains an integer t, the number of test cases. t test cases follow.

For each test case, in the first line there are two positive integers N (N≤100000) and M (M≤500000), as described above. The i-th line of the next N lines contains an integer ai(∀i,0≤ai≤10000) representing the number of the i-th lake.

The i-th line of the next M lines contains two integers ui and vi representing the i-th river between the ui-th lake and vi-th lake. It is possible that ui=vi.


Output
For each test cases, output the largest lucky number. If it dose not have any path, output "Impossible".


Sample Input
2
3 2
3
4
5
1 2
2 3
4 3
1
2
3
4
1 2
2 3
2 4


Sample Output
2
Impossible


大意:給出N個點M條邊的圖,每條邊只能經過一次,求出通路的每個點異或得到的最大值


解題思路:這是一個典型的歐拉圖,所以首先要判斷給出的是不是歐拉圖,其次判斷是歐拉通路還是歐拉回路,歐拉通路用(2degreeu mod 2)au

計算貢獻幾次,只有0,1,兩種答案,因爲貢獻不分先後順序。這裏用到了一個向上取整的思想,因爲奇度點也貢獻一次, 那麼歐拉回路只需要枚舉一下起點就好


代碼:

<span style="font-size:18px;">#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
int du[100010];
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        for(int i = 1; i<= n; i++)
        {
            scanf("%d", &a[i]);
        }
        int u,v;
        memset(du,0,sizeof(du));
        for(int i = 1; i<= m; i++)
        {
            scanf("%d%d", &u, &v);
            du[u]++;
            du[v]++;
        }
        ///判斷有幾個奇度點
        int odd = 0;
        for(int i = 1; i<= n; i++)
        {
            if(du[i] %2 != 0)
                odd++;
        }
        ///歐拉通路
        if(odd == 0 || odd== 2)
        {
            int ans = 0;
            for(int i = 1; i<= n; i++)
                ans ^= (((du[i] + 1) / 2) % 2) * a[i];
            ///歐拉回路
            if(odd == 0)
            {
                int maxn = ans ^ a[1];
                for(int i = 2; i<= n; i++)
                {
                    maxn = max(maxn , ans ^ a[i]);
                }
                ans = maxn;
            }
            printf("%d\n", ans);
        }
        else
            printf("Impossible\n");
}
    return 0;
}</span><span style="font-size: 16.94px;">
</span>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章