ACM学习历程—BestCoder Round #75

1001:King‘s Cake(数论)

http://acm.hdu.edu.cn/showproblem.php?pid=5640

这题有点辗转相除的意思。基本没有什么坑点。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long

using namespace std;

int n, m;

int main()
{
    //freopen("test.in", "r", stdin);
    int T;
    scanf("%d", &T);
    for (int times = 1; times <= T; ++times)
    {
        scanf("%d%d", &n, &m);
        int ans = 0;
        while (n&&m)
        {
            if (n > m) swap(n, m);
            ans += m/n;
            m = m%n;
        }
        printf("%d\n", ans);
    }
    return 0;
}

1002:King‘s Phone(模拟)

http://acm.hdu.edu.cn/showproblem.php?pid=5641

这题坑点有点多,3A。。首先任意一条连线,需要判断中间有没有经过什么点。

然后不能有重复的点,需要判断。

其次,对于0和大于9的数据需要判断掉。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long

using namespace std;

int k, s[10];
bool vis[10];

int cross(int from, int to)
{
    if (from > to) swap(from, to);
    if (from == 1 && to == 3) return 2;
    if (from == 1 && to == 7) return 4;
    if (from == 1 && to == 9) return 5;
    if (from == 2 && to == 8) return 5;
    if (from == 3 && to == 7) return 5;
    if (from == 4 && to == 6) return 5;
    if (from == 3 && to == 9) return 6;
    if (from == 7 && to == 9) return 8;
    return 0;
}

bool work()
{
    if (k < 4) return false;
    memset(vis, false, sizeof(vis));
    int t;
    for (int i = 1; i < k; ++i)
    {
        if (s[i-1] == 0 || s[i] == 0) return false;
        if (s[i-1] > 9 || s[i] > 9) return false;
        if (s[i] == s[i-1]) return false;
        if (vis[s[i]]) return false;
        t = cross(s[i-1], s[i]);
        if (t && !vis[t]) return false;
        vis[s[i-1]] = true;
        vis[s[i]] = true;
    }
    return true;
}

int main()
{
    //freopen("test.in", "r", stdin);
    int T;
    scanf("%d", &T);
    for (int times = 1; times <= T; ++times)
    {
        scanf("%d", &k);
        for (int i = 0; i < k; ++i)
            scanf("%d", &s[i]);
        if (work()) printf("valid\n");
        else printf("invalid\n");
    }
    return 0;
}

1003:King‘s Order(递推)

http://acm.hdu.edu.cn/showproblem.php?pid=5642

这题是个递推,但是没考虑清楚,递推式一直是错的,4A。。

设p[n][k]表示n长度字符串,结尾k个相同的情况数。

那么:

p[i][1] = 25*(p[i-1][1]+p[i-1][2]+p[i-1][3])%MOD;

p[i][2] = p[i-1][1];

p[i][3] = p[i-1][2];

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long
#define MOD 1000000007

using namespace std;

const int maxN = 2005;
int n;
LL p[maxN][5];

void init()
{
    p[1][1] = 26;
    p[1][2] = 0;
    p[1][3] = 0;
    for (int i = 2; i < maxN; ++i)
    {
        p[i][1] = 25*(p[i-1][1]+p[i-1][2]+p[i-1][3])%MOD;
        p[i][2] = p[i-1][1];
        p[i][3] = p[i-1][2];
    }
}

int main()
{
    //freopen("test.in", "r", stdin);
    init();
    int T;
    scanf("%d", &T);
    for (int times = 1; times <= T; ++times)
    {
        scanf("%d", &n);
        cout << (p[n][1]+p[n][2]+p[n][3])%MOD << endl;
    }
    return 0;
}

1004:King‘s Game(递推)

http://acm.hdu.edu.cn/showproblem.php?pid=5643

这一题想法类似于O(n)做法的约瑟夫问题。需要考虑子问题,然后映射回来。具体的方法百度百科里有。

最后

p(n, k) = (p(n-1, k+1)+k)%n  or  n(if 0)

不过我二逼的离线了一发,然后MLE了。。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long

using namespace std;

const int maxN = 5001;
/*
int p[maxN][maxN];

void init()
{
    for (int i = 0; i < maxN; ++i)
        p[1][i] = 1;
    for (int i = 2; i < maxN; ++i)
    {
        for (int j = 1; j < maxN; ++j)
        {
            p[i][j] = (p[i-1][j+1]+j)%i;
            if (!p[i][j]) p[i][j] = i;
        }
    }
}
*/

int dfs(int n, int k)
{
    if (n == 1) return 1;
    int ans;
    ans = (dfs(n-1, k+1)+k)%n;
    if (!ans) ans = n;
    return ans;
}

int main()
{
    //freopen("test.in", "r", stdin);
    //init();
    int n, T;
    scanf("%d", &T);
    for (int times = 1; times <= T; ++times)
    {
        scanf("%d", &n);
        printf("%d\n",dfs(n, 1));
    }
    return 0;
}

1005:没有想法。。应该是水平还没到火候。。。

时间: 2024-12-15 20:55:12

ACM学习历程—BestCoder Round #75的相关文章

ACM学习历程—BestCoder 2015百度之星资格赛1001 大搬家(递推 &amp;&amp; 组合数学)

Problem Description 近期B厂组织了一次大搬家,所有人都要按照指示换到指定的座位上.指示的内容是坐在位置i 上的人要搬到位置j 上.现在B厂有N 个人,一对一到N 个位置上.搬家之后也是一一对应的,改变的只有位次. 在第一次搬家后,度度熊由于疏忽,又要求大家按照原指示进行了一次搬家.于是,机智的它想到:再按这个指示搬一次家不就可以恢复第一次搬家的样子了.于是,B厂史无前例的进行了连续三次搬家. 虽然我们都知道度度熊的“机智”常常令人堪忧,但是不可思议的是,这回真的应验了.第三次

ACM学习历程—BestCoder 2015百度之星资格赛1002 列变位法解密(vector容器)

Problem Description 列变位法是古典密码算法中变位加密的一种方法,具体过程如下 将明文字符分割成个数固定的分组(如5个一组,5即为密钥),按一组一行的次序整齐排列,最后不足一组不放置任何字符,完成后按列读取即成密文. 比如: 原文:123456789 密钥:4 变换后的矩阵: 1234 5678 9xxx (最后的几个x表示无任何字符,不是空格,不是制表符,就没有任何字符,下同) 密文:159263748 再比如: 原文:Hello, welcome to my dream w

ACM学习历程—BestCoder 2015百度之星资格赛1003 IP聚合(set容器)

Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网络地址等于子网掩码与 IP 地址按位进行与运算后的结果,例如: 子网掩码:A.B.C.D IP 地址:a.b.c.d 网络地址:(A&a).(B&b).(C&c).(D&d) Input 第一行包含一个整数T ,(1≤T≤50) 代表测试数据的组数, 接下来T 组测试数据.每组

ACM学习历程—HDU 5023 A Corrupt Mayor&#39;s Performance Art(广州赛区网赛)(线段树)

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money. Becaus

BestCoder Round #75 - King&#39;s Phone

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

ACM学习历程—HDU 4726 Kia&#39;s Calculation( 贪心&amp;&amp;计数排序)

DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds 9. For example, when she calculates 4567+5789, she will get 9246, and for 12

BestCoder Round #75 King&amp;#39;s Order dp:数位dp

King's Order Accepts: 381 Submissions: 1361 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description After the king's speech , everyone is encouraged. But the war is not over. The king needs to give orders

ACM学习历程—UESTC 1226 Huatuo&#39;s Medicine(数学)(2015CCPC L)

题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #

ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now