zoukankan      html  css  js  c++  java
  • Codeforces 849 C From Y to Y 思维

      题目链接: http://codeforces.com/contest/849/problem/C

      题目描述: 给你个一个cost, 让你构造花费为cost的字符串, 每次的 cost = 两个元素公共元素个数乘积

      解题思路: 很明显发现仅仅一个字母可以构造1, 3, 6, 10......两个不同的字符不会得到cost, 所以我们就先构造一种字母, 不行的用下一个字母填充就可以了......

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iterator>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <deque>
    #include <map>
    #include <set>
    #define lson l, m, rt<<1
    #define rson m+1, r, rt<<1|1
    #define mem0(a) memset(a,0,sizeof(a))
    #define sca(x) scanf("%d",&x)
    #define de printf("=======
    ")
    typedef long long ll;
    using namespace std;
    
    int main() {
        int n;
        cin.sync_with_stdio(false);
        string str;
        while( cin >> n ) {
            char c = 'a';
            int num;
            str = "";
            if( n == 0 ) {
                cout << "a" << endl;
                continue;
            }
            while( n ) {
                num = 0;
                while( num <= n ) {
                    n -= num;
                    str += c;
                    num++;
                }
                c++;
            }
            cout << str << endl;
        }
        return 0;
    }
    View Code

      思考: 我一直不知道为什么, 看起来很显眼的东西我却总是想不到......我打算以后接触一下思维题, 心态炸了......但是还是要控制一下

  • 相关阅读:
    数据库乐观锁应用
    maven 引入本地jar
    GTS 分布式事务
    redis 做冥等
    服务器 启动命令
    pgAdmin4的应用
    PostgreSQL 分区
    压测工具
    BigDecimal 比较大小
    移动端px转化为rem
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7468761.html
Copyright © 2011-2022 走看看