青岛网络赛部分题解

题目链接: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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值