首页 > 其他分享 >AtCoder Beginner Contest 319

AtCoder Beginner Contest 319

时间:2024-04-17 11:44:17浏览次数:26  
标签:AtCoder 319 Beginner int auto cin i64 vi using

A - Legendary Players

#include<bits/stdc++.h>

using namespace std;

int main() {
    map<string, string> h;
    h["tourist"] = "3858";
    h["ksun48"] = "3679";
    h["Benq"] = "3658";
    h["Um_nik"] = "3648";
    h["apiad"] = "3638";
    h["Stonefeang"] = "3630";
    h["ecnerwala"] = "3613";
    h["mnbvmar"] = "3555";
    h["newbiedmy"] = "3516";
    h["semiexp"] = "3481";
    string s;
    cin >> s;
    cout << h[s] << "\n";
    return 0;
}

B - Measure

#include<bits/stdc++.h>

using namespace std;

int main() {
    map<string, string> h;
    int n;
    cin >> n;
    for (int i = 0, f; i <= n; i++) {
        f = 1;
        for( int j = 1 ; f and j <= 9 ; j ++ ){
            if( n % j ) continue;
            if( i % ( n / j ) ) continue;
            cout << j , f = 0;
        }
        if(f) cout << "-";
    }
    return 0;
}

C - False Hope

给定一个\(3\times 3\)的矩阵,保证任意行、列、对角线不会出现三个相同的情况。一开始,矩阵为空,每次可以随机的填入一个数,如果出现任意行、列、对角线填入的前两个值相同,就会失望。问不失望的概率。

因为这道题目的填入顺序只有\(9!\)种,所以可以暴力的枚举,然后检查就好了。

#include<bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

using vi = vector<int>;


int main() {
    vi a(9), b(9);
    for (auto &i: a) cin>> i;
    iota(b.begin(), b.end(), 0);
    vector<vi> l = {{0, 1, 2},
                    {3, 4, 5},
                    {6, 7, 8},
                    {0, 3, 6},
                    {1, 4, 7},
                    {2, 5, 8},
                    {0, 4, 8},
                    {2, 4, 6}};

    double x = 0, y = 0;
    do {
        int ok = 1;
        for (const auto li: l) {
            vi f;
            for (const auto &i: b)
                if (ranges::count(li, i)) f.push_back(a[i]);
            if( f[0] == f[1] ) ok = 0;
        }
        x += ok, y += 1;
    } while (next_permutation(b.begin(), b.end()));
    cout << fixed << setprecision(20) << x / y << "\n";
    return 0;
}

D - Minimum Width

二分答案,然后\(O(n)\)的check一下

#include<bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

#define int i64

using vi = vector<int>;

const i64 inf = 1e15;

i32 main() {
	ios::sync_with_stdio(false) , cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vi a(n);
	for(auto &i : a) cin >> i;
	int l = ranges::max(a) , r = inf, res = -1;
	auto check = [=](int x) -> bool {
		int cnt = 0 , used = x;
		for(const auto &i : a){
			if(used + 1 + i > x) cnt ++ , used = i;
			else used += 1 + i;
		}
		return cnt <= m;
	};

    while(l <= r){
    	int mid = (l + r) / 2;
    	if( check(mid) ) res = mid, r = mid - 1;
    	else l = mid + 1;
    }
    cout << res << "\n";
    return 0;
}

E - Bus Stops

值得注意的一点就是,每个公交车只能从\(i\)走到\(i+1\),这样的话求出\(P_i\)的最小公倍数,然后枚举出所有的情况即可。

#include<bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

#define int i64

using vi = vector<int>;
using pii = pair<int,int>;

const i64 inf = 1e15;

i32 main() {
	ios::sync_with_stdio(false) , cin.tie(nullptr);
	int n, x, y;
	cin >> n >> x >> y , n --;
	vector<pii> city(n);
	int d = 1;
	for(auto &[p,t] : city) cin >> p >> t , d = lcm(d , p);
	vi dis(d);
	for( int i = 0 ; i < d ; i ++ ){
		dis[i] = i + x;
		for(const auto &[p,t] : city){
			while(dis[i] % p) dis[i] ++;
			dis[i] += t;
		}
		dis[i] += y - i;
	}
    int q;
    cin >> q;
    for(int x ; q ; q --){
    	cin >> x;
    	cout << x + dis[x%d] << "\n";
    }
    return 0;
}

标签:AtCoder,319,Beginner,int,auto,cin,i64,vi,using
From: https://www.cnblogs.com/PHarr/p/18140240

相关文章

  • Atcoder赛后反思
    先贴上本人主页目录ABC347\(\tiny\color{blue}1624\color{red}-24\color{black}=\color{blue}1600\)AGC066\(\tiny\color{blue}1600\color{red}-21\color{black}=\color{cyan}1579\)ABC348\(\tiny\color{cyan}1579\color{green}+114\color{black}=\color{blu......
  • [题解](A-G)Atcoder Educational DP Contest(更新中)
    AtcoderEducationalDPContest\(\textbf{A.Frog1}\)对于一块石头\(i(3\lei\leN)\),\(i-1\)和\(i-2\)均能到达。用\(f[i]\)表示跳到第\(i\)个石头用的最小体力消耗:\[f[i]=min(abs(h[i]-h[i-1])+f[i-1],abs(h[i]-h[i-2])+f[i-2])\qquadi\ge3\]时间复杂度\(O(n)\)。......
  • AtCoder Beginner Contest 347
    B-Substring难度:⭐题目大意给你一个由小写英文字母组成的字符串S;请问S有多少个不同的非空子串?解题思路数据很小,暴力就行;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#defi......
  • AtCoder Beginner Contest 346
    B-Piano难度:⭐⭐题目大意现有S为无限重复字符串"wbwbwwbwbwbw"形成的字符串。请问S中是否存在由W次出现的'w'和B次出现的'b'组成的子字符串T;解题思路字符串T显然可以由S的一段后缀+若干个S+S的一段前缀组成;但是,这个题的W和B都最大为100;也就是说,如果存......
  • [ABC349] AtCoder Beginner Contest 349 题解
    [ABC349]AtCoderBeginnerContest349题解目录[ABC349]AtCoderBeginnerContest349题解A-ZeroSumGameB-CommencementC-AirportCodeD-DivideIntervalE-WeightedTic-Tac-ToeF-SubsequenceLCMG-PalindromeConstruction总结A-ZeroSumGame零和博弈,......
  • AtCoder Beginner Contest 349
    B-Commencement难度:⭐题目大意给定一个字符串,问这个字符串中出现的字母是否都恰好为0个或者2个;解题思路数据很小,暴力就行;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#def......
  • AtCoder Beginner Contest 349
    A-ZeroSumGame(abc349A)题目大意\(n\)个人游戏,每局有一人\(+1\)分,有一人\(-1\)分。给定最后前\(n-1\)个人的分数,问第\(n\)个人的分数。解题思路零和游戏,所有人总分是\(0\),因此最后一个人的分数就是前\(n-1\)个人的分数和的相反数。神奇的代码n=input()prin......
  • AtCoder Beginner Contest 347
    A-Divisible#include<bits/stdc++.h>usingnamespacestd;usingi32=int32_t;usingi64=longlong;#defineinti64usingvi=vector<i64>;usingpii=pair<int,int>;usingpiii=tuple<int,int,int>;constintinf=1e......
  • atcoder beginer 347 (abc347) D E 题解
     D就是二进制下,哪些位置有重合(两个1),哪些位置没有重合(1个1,1个0),剩下的都是0。xor的结果<2^60,就是小于60位(二进制下)。注意要有要求两个数需要是2^60,于是要有大小的判断,因为有的a,b会2^60,但是按照题目要求,这个情况不行。比如xor的结果,60位都是1,然后a、b各有60个1,那么需要有30个1......
  • atcoder beginer 348 (abc348) D E F 题解
     E非常经典的树上操作(树上DP)。父节点到某个子节点,值是如何变化的。1#include<cstdio>2#include<cstdlib>3#include<cstring>4#include<cmath>5#include<cstdbool>6#include<string>7#include<algorithm>8#include<iost......