Codeforces Global Round 8 ABC

Codeforces Global Round 8 ABC

A - C+=

题意

给定 a , b , n a, b, n a,b,n ,每次可以进行 a = a + b a = a + b a=a+b b = b + a b = b + a b=b+a 的操作。问至少操作多少次,可以使 a , b a, b a,b 中一个数大于等于 n n n

思路

每次操作无论是 a = a + b a = a + b a=a+b 还是 b = b + a b = b + a b=b+a ,得到的数都是 a + b a + b a+b ,所以其实只需要考虑替换掉 a a a 还是 b b b 。显然,一定是替换较小的那个。直接暴力替换直至满足条件即可。

代码

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e5 + 19;
const ll mod = 1e9 + 7;

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int a, b, n;
        int tmp;
        cin >> a >> b >> n;
        int cnt = 1;
        while(a + b <= n)
        {
            tmp = a + b;
            a = max(a, b);
            b = tmp;
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

B - Codeforces Subsequences

题意

给定数字 k k k ,要求你给出长度最短的字符串,使得该字符串中至少有 k k k 个不同的子串是 “ c o d e f o r c e s ” “codeforces” codeforces

思路

最开始 “codeforces” 中每个元素都只出现了一次,之后我们按顺序给每个字符个数+1,并随时判断当前个数有没有大于 k k k ,加完一轮后还是不满足就返回开头继续一个一个加,像铺床一样一层一层铺,直到当前个数大于 k k k

对于这一类输入只有一个数字的题目一定要先拿最大值试一下,不要等T了才知道问题,甚至FST了才知道问题,那就太可惜了qwq(我的第一发就是因为没开longlong导致溢出,然后死循环T了,还一直找不出问题,最后写了两版代码)

代码

实例1
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e4 + 19;
const ll mod = 1e9 + 7;

string str = "codeforces";

int main()
{
    ll k;
    cin >> k;
    if(k == 1)
    {
        cout << str << endl;
        return 0;
    }
    ll tmp = 1;
    int n = str.length();
    for(int time = 2; ; time++)
    {
        for(int pos = 0; pos < n; pos++)
        {
            tmp = tmp / (time - 1) * time;
            if(tmp >= k)
            {
                for(int i = 0; i <= pos; i++)
                {
                    for(int j = 0; j < time; j++)
                    {
                        cout << str[i];
                    }
                }
                for(int i = pos + 1; i < n; i++)
                {
                    for(int j = 0; j < time - 1; j++)
                    {
                        cout << str[i];
                    }
                }
                return 0;
            }
        }
    }
    return 0;
}
实例2(没有1优美)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e5 + 19;
const ll mod = 1e9 + 7;

ll qpow(int x, int n)
{
    ll ans = 1;
    while(n)
    {
        if(n & 1)
        {
            ans *= x;
        }
        n >>= 1;
        x *= x;
    }
    return ans;
}

string str = "codeforces";

int main()
{
    ll k;
    cin >> k;
    ll tmp = 1;
    int pos1 = 1;//pre
    int pos2 = 2;
    int n = str.length();
    bool flag = 0;
    int num = 0;
    while(k > tmp)
    {
        num = 0;
        for(int i = 0; i < n; i++)
        {
            tmp = tmp / pos1 * pos2;
            num++;
            if(k <= tmp)
            {
                flag = 1;
                break;
            }
        }
        if(flag)
            break;
        pos1 = pos2;
        pos2++;
    }
    for(int i = 0; i < n; i++)
    {
        if(num)
        {
            for(int j = 0; j < pos2; j++)
            {
                cout << str[i];
            }
            num--;
        }
        else
        {
            for(int j = 0; j < pos1; j++)
            {
                cout << str[i];
            }
        }
    }
    cout << endl;
    return 0;
}

C - Even Picture

题意

在方格纸上涂灰一些方格,使得以下条件全部满足:

  • 灰格子是连通的,即所有的灰格子都有其他灰格子与其共享边(一条或多条);
  • 每个灰格子都与偶数个灰色格子为邻;
  • 刚好有 n n n 个灰色格子四周均为灰色格子(这个表达真是当时没有看懂。。。)。其他灰色格子的数量是随意的,但是必须是有限个,这样才能答案中被表示出来。

思路

不看题解真的想不到系列。

在这里插入图片描述

代码

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e5 + 19;
const ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    cout << n + n + n + 4 << endl;
    for(int i = 0; i <= n + 1; i++)
    {
        cout << i << ' ' << i << endl;
    }
    for(int i = 0; i <= n; i++)
    {
        cout << i << ' ' << i + 1 << endl;
    }
    for(int i = 0; i <= n; i++)
    {
        cout << i + 1 << ' ' << i << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值