Codeforces Round #491 (Div. 2) — 赛后补题

C. Candies

PS:大概是又傻了,读题啊。

#include<bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define pb push_back
#define lson root << 1
#define INF (int)2e9 + 7
#define maxn (int)1e5 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

ll n;

bool check(ll mid){
    ll res = 0;
    ll tp = n;
    while(tp){
        if(tp < mid) break;

        res += mid;
        tp = tp - mid;
        tp = tp - tp / 10;
    }
    res += tp;
    if(res * 2 >= n) return true;
    return false;
}

int main()
{
    cin >> n;
    ll l = 1, r = n;
    for(int i = 1; i <= 100; i++){
        ll mid = (l + r) >> 1;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}

D. Bishwock

PS:又FST了,读题的锅。从头依次寻找合法的位置放就行了。因为所有能放的位置在贪心的过程中都会被找到,故一定是最优解。

#include<bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define pb push_back
#define lson root << 1
#define INF (int)2e9 + 7
#define maxn (int)1e5 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

char mp[2][200];

int main()
{
    for(int i = 0; i < 2; i++) scanf("%s", mp[i]);
    int n = strlen(mp[0]);
    int res = 0;
    for(int i = 0; i < n - 1; ){
        int t = 0;
        if(mp[0][i] == ‘X‘) t++;
        if(mp[1][i] == ‘X‘) t++;
        if(mp[0][i + 1] == ‘X‘) t++;
        if(mp[1][i + 1] == ‘X‘) t++;
        if(t > 1){
            i++;
            continue;
        }
        else{
            i += 2;
            res++;
        }

        int tt = 0;
        if(i < n - 2){
            if(mp[0][i] == ‘X‘) tt++;
            if(mp[1][i] == ‘X‘) tt++;
            if(t == 0 && tt == 0){
                i += 1;
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

E. Bus Number

PS:去重排列的公式得知道。然后暴力枚举,可以用10个循环,也可以深搜。写搜索很考验状态的设计,还有考虑什么时候终止,在哪里计算答案等等。

PS:非本人原创#include<bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define pb push_back
#define pop pop_back
#define lson root << 1
#define INF (int)2e9 + 7
#define maxn (int)1e5 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

int a[20];
ll n, res, fac[20];

vector<int> d;      //记录每个数使用了多少次

void Inite()
{
    res = 0;
    fac[0] = 1;
    for(int i = 1; i < 20; i++) fac[i] = fac[i - 1] * i;
}

ll C(ll x, ll y){
    return fac[x] / fac[y] / fac[x - y];
}

void DFS(int x){
    if(x == 10){
        ll s = 0, tp = 0;
        for(auto o : d) s += o;
        tp = fac[s];
        for(auto o : d) tp /= fac[o];

        if(!a[0]){
            res += tp;
            return;
        }
        else{
            for(int i = 1; i <= a[0]; i++) res += tp * C(s + i - 1, i);
            return;
        }
    }
    if(!a[x]) DFS(x + 1);
    for(int i = 1; i <= a[x]; i++){
        d.pb(i);
        DFS(x + 1);
        d.pop();
    }
}

int main()
{
    Inite();
    cin >> n;
    while(n) {
       a[n % 10]++;
       n /= 10;
    }
    DFS(1);
    cout << res << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/zgglj-com/p/9224563.html

时间: 2024-08-03 10:56:59

Codeforces Round #491 (Div. 2) — 赛后补题的相关文章

Codeforces Round #490 (Div. 3)-赛后补题

D. Equalize the Remainders 思维太僵硬了,我从余数入手,嫩是记录不了每个数要操作多少次.但是如果考虑每个数的贡献,即操作多少次能使得满足条件,就好写了,实际上也是暴力. #include<bits/stdc++.h> #define ll long long #define P pair<int,int> #define pb push_back #define lson root << 1 #define INF (int)2e9 + 7 #

Educational Codeforces Round 48 (Rated for Div. 2) - 赛后补题

C. Vasya And The Mushrooms 题解:拿笔画他的行走路线,你会发现可以前缀和预处理一些东西出来. const int N = 300005; int n; ll a[N], b[N], dp[2][N], sp[2][N], sum[N]; int get_a() { dp[0][0] = 0; for (int i = 1; i < n; ++i) { dp[0][i] = dp[0][i - 1] + 1ll * i * a[i]; } int t = n; dp[1]

Educational Codeforces Round 24 CF 818 A-G 补题

6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子,一直坚持刷题,这一个学期刷了200道吧,感觉还是小有收获.特别是Ural和Codeforces上的题,质量很高. 然后4月的校赛,5月的省赛,发挥的也一般,不过也没有太失常. 希望暑假的选拔赛能碰到有趣的队友 蛤蛤. 这两天各种考试,实在是太忙,看了一下edu24的题目,不是很容易,做了一道水题,以

Codeforces Round #315 (Div. 2) (ABCD题)

A. Music 题意: 一首歌长度为S秒,已经下载了T秒,下载速度为每q秒的现实时间能下载下来(q-1)秒 的歌曲.现在开始听歌,如果听到还没下载的地方就从0秒的地方开始replay,求一首歌听完需要从0秒听几次(包括一开始那次) 思路: 我们可以用路程-时间的思路来考虑这道题. 假设两位选手"播放"与"下载","播放"的起点是0m处,"下载"的起点是Tm处,终点在Sm处,"播放"的速度是1m/s,&qu

Codeforces Round #310 (Div. 2)--A(简单题)

http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少个,最后答案就是两者不同的个数. #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algo

Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉

司老大当时教了一种姿势枚举连续K个0,说实话当时比赛写这题完全蒙了 纵然后来知道思路还是写了一段时间 真的是.. 题目大意 n长度的序列,由0 1构成 我们可以改变 k个0为1 求可以得到的最长连续1序列的长度 既然求连续1 我们贪心连续k个0 枚举端点 左端点0设置为0 右端点0设置为 n+1 中间统计一下 最长长度和改变的0的位置就OK了 1 #include<cstdio> 2 #include<map> 3 //#include<bits/stdc++.h> 4

Codeforces Round #345 (Div. 2) D 细节题

这个题的意思是给你n张首尾相接的照片, 当前照片在1, 每次只能转移一个单位, 转移时间为a, 照片有可能颠倒, 将照片摆正需要的时间为b, 看照片的时间为1, 想要看尽可能多的照片, 问这个数量是多少, 我们可以预处理查看每张照片需要的时间, 然后枚举从左边看需要的时间, 从右边看需要的时间, 二分从另外一边看需要的时间即可, 代码如下: #include <cstdio> #include <algorithm> #include <cstring> using n

Codeforces Round #316 (Div. 2) (ABC题)

A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利: 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序),第一位获得胜利: 求最后选举获胜者. 思路: 直接模拟即可. 代码: /* * @author FreeWifi_novicer * language : C++/C */ #include<cstdio> #include<iostream> #include<cstring

Codeforces Round #491 (Div. 2) E - Bus Number + 反思

E - Bus Number 最近感觉打CF各种车祸.....感觉要反思一下, 上次读错题,这次想当然地以为18!肯定暴了longlong 而没有去实践, 这个题我看到就感觉是枚举每个数字的个数,但是我觉得算得时候会爆longlong 就想用大数,但是我去看别人交的全部都是C++,就感觉是不是有别的方法, 想了半天感觉时间来不及了就强行上了个java,结果时间来不及... 以后写题首先要读清楚题目,其次不要想当然,要去实践!!!!!!!!!!! 真的很烦. import java.math.Bi