2017HDU多校7场

题目链接


01:http://acm.hdu.edu.cn/showproblem.php?pid=6120
02:http://acm.hdu.edu.cn/showproblem.php?pid=6121
03:http://acm.hdu.edu.cn/showproblem.php?pid=6122
04:http://acm.hdu.edu.cn/showproblem.php?pid=6123
05:http://acm.hdu.edu.cn/showproblem.php?pid=6124
06:http://acm.hdu.edu.cn/showproblem.php?pid=6125
07:http://acm.hdu.edu.cn/showproblem.php?pid=6126
08:http://acm.hdu.edu.cn/showproblem.php?pid=6127
09:http://acm.hdu.edu.cn/showproblem.php?pid=6128
10:http://acm.hdu.edu.cn/showproblem.php?pid=6129
11:http://acm.hdu.edu.cn/showproblem.php?pid=6130
12:http://acm.hdu.edu.cn/showproblem.php?pid=6131
13:http://acm.hdu.edu.cn/showproblem.php?pid=6132
本次比赛又是三题,可惜最后10的规律没有明确。

一些题解


05 Euler theorem

 本场的水题,给定一个a问任意的b让a % b有几种可能的值。
 可以得见0 - (a / 2 - 1)都是可以得到的值, 而且其本身也是可以得到的值所以得到代码。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int a;
        scanf("%d", &a);
        int ans;
        if(a % 2 == 0)
            ans = a / 2 + 1;
        else
            ans = (a + 1) / 2 + 1;
        printf("%d\n", ans);
    }
    return 0;
}

08 Hard challenge

 题意是说有n个点,每两个点都不在一条直线上,把每两个点相连,其边的权值就是给定的两个点的值的乘积。现在从原点做一条直线问这条直线所穿过的所有边的权值的和最大是多少。
 可以把点分作左右两边来对待,而左右两边点的权值之和就是(A + B + C +…) * (a + b + c + ….)。我们将图分为上下两块,然后把角度大于180°的点角度减去180°,并标记点是上面的点还是下面的点。按角度排序从小到大扫一遍。当扫到的点是上面的点时,sum上 - point.value, sum下 + point.value;当扫到下面的点相反即可。再相乘求其最大值。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define rep(i, s, t) for(int i = s;i <= t;i++)
#define rap(i, s, t) for(int i = s;i >= t;i--)
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
struct point
{
    double x, y;
    double angle;
    LL value;
    int flag;
}p[50005];
int n;
int cmp(point a, point b)
{
    return a.angle < b.angle;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        LL maxn = 0;
        LL sumu = 0,  sumd = 0;
        scanf("%d", &n);
        rep(i, 1, n){
            scanf("%lf%lf%I64d", &p[i].x, &p[i].y, &p[i].value);
            if(p[i].y >= 0)
                p[i].flag = 1, sumu += p[i].value;
            else
                p[i].flag = 0, sumd += p[i].value;
            double pp = acos(p[i].x / sqrt(p[i].x * p[i].x + p[i].y * p[i].y));
            pp = pp * 180 / PI;
            if(p[i].flag == 0)
                p[i].angle = 180 - pp;
            else
                p[i].angle = pp;
        }
        sort(p + 1, p + 1 + n, cmp);
        rep(i, 1, n){
            if(p[i].flag == 1)
            {
                sumu -= p[i].value;
                sumd += p[i].value;
            }
            else
            {
                sumd -= p[i].value;
                sumu += p[i].value;
            }
            maxn = max(maxn, sumd * sumu);
        }
        printf("%I64d\n", maxn);
    }
    return 0;
}

11 Kolakoski

 题意是求Kolakoski序的第n个值,一开始妄图使用Kolakoski序的性质即a(a(1) + a(2) + a(3) + a(k)) = (3 + (-1)^k) / 2发现超时且没必要,直接模拟其定义即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10000004];
int main()
{
    a[1] = 1;
    a[2] = 2;
    a[3] = 2;
    int ans = 4;
    int right = 3;
    while(ans <= 10000000)
    {
        if(a[right] == 2&&a[ans - 1] == 2)
            a[ans++] = 1, a[ans++] = 1;
        else if(a[right] == 2&&a[ans - 1] == 1)
            a[ans++] = 2, a[ans++] = 2;
        else if(a[right] == 1)
        {
            if(a[ans - 1] == 2)
                a[ans++] = 1;
            else
                a[ans++] = 2;
        }
        right++;
    }
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        printf("%d\n", a[n]);
    }
    return 0;
}

下面是后来补的题

02 Build a tree

 这题当时写k叉树没搞定网上搜的题解真是巧妙进行满编,非满编,满编却少一层的标记,然后每次更新状态,由下至上统计即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;

int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        LL n, k;
        LL ans;
        LL s1, s2, s3, n1, n2, n3;
        scanf("%lld%lld", &n, &k);
        ans = 0;
        s1 = n1 = s2 = n2 = s3 = n3 = 0;
        if(k == 1)
        {
            if(n % 4 == 1)
                printf("1\n");
            else if(n % 4 == 2)
                printf("%I64d\n", n + 1);
            else if(n % 4 == 3)
                printf("0\n");
            else if(n % 4 == 0)
                printf("%I64d\n", n);
            continue;
        }
        LL ls = 1;
        while(n > 0)
        {
            n -= ls;
            if(n / ls < k)
                break;
            ls *= k;
        }
        if(n)
        {
            n1 = n;
            s1 = 1;
            if(n&1)
                ans = 1;
        }
        while(ls > 0)
        {
            if(n1 < k)//此时将不会再有单独的满员状态,将n1和n2状态合并
            {
                s1 = n1 * s1 + s2 + s3 * (k - n1 - n2) + 1;
                n1 = 1;
                n2 = 0;
                s2 = 0;
            }
            else
            {
                if(n1 % k)
                {
                    s2 = n1 % k * s1 + (k - n1 % k - n2) * s3 + s2 + 1;
                    n2 = 1;
                }
                else if(n2)
                {
                    s2 = s2 + (k - 1) * s3 + 1;
                }
                s1 = s1 * k + 1;
                n1 = n1 / k;
            }
            s3 = s3 * k + 1;
            n3 = ls - n1 - n2;
            if(n1 & 1)ans ^= s1;
            if(n2 & 1)ans ^= s2;
            if(n3 & 1)ans ^= s3;
            ls /= k;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}

10 Just do it

 这道题的题意是说给定一个ai然后每一个bi都a1^a2^….ai问这样进行m次后最终得到的数列序列是什么。
 由异或性质可知一个数的奇数个异或就为本生,偶数个异或为0。在比赛时打表直接简化为01表了,虽然发现了4进制的规律但是并没有别的发现,而且写法复杂。赛后队友发现是保留原来的系数发现就是杨辉三角斜着下来。而判断Cmn是否为奇数的方法是M&N == N?奇数:偶数。而每一个i,m所对应的M就是i + m - 2,N就是i - 1(表中规律),这样就可以得到所要异或的值。
 之后i从1到n遍历,但是其所代表的其实是an-a1然后对每个可以到达第i个的数,他们在第i个的系数都是一样的,所以再遍历异或即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define rep(i, s, t) for(int i = s;i <= t;i++)
#define rap(i, s, t) for(int i = s;i >= t;i--)
using namespace std;
typedef long long LL;
int n, m;
LL stand[200004];
LL ans[200004];
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        memset(stand, 0, sizeof(stand));
        memset(ans, 0, sizeof(ans));
        scanf("%d%d", &n, &m);
        rep(i, 1, n)
            scanf("%I64d", &stand[i]);
        rep(i, 1, n)
        {
            int nn = m + i - 2;
            int mm = i - 1;
            if((nn & mm) == mm)
                rep(j, i, n)
                    ans[j] ^= stand[j - i + 1];
        }
        rep(i, 1, n)
            printf("%I64d%c", ans[i], i == n?'\n':' ');
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值