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

AtCoder Beginner Contest 072

时间:2023-06-27 14:22:53浏览次数:40  
标签:AtCoder cnt 072 cout Beginner int res cin long

A - Sandglass2

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    int a , b;
    cin >> a >> b;
    cout << max( a - b , 0ll );
    return 0;
}

B - OddString

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    string s;
    cin >> s;
    for( int i = 0 ; i < s.size() ; i += 2 )
        cout << s[i];
    return 0;
}

C - Together

这里注意到数字的个数只有\(10^5\),所以最多能够作为答案也不多,并且数字的范围也不大,直接枚举作为答案的值,然后统计一下就好。

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 1e5;

int32_t main() {
    ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> cnt( N );
    for( int x ; n ; n -- )
        cin >> x , cnt[x] ++;
    int res = 1;
    for( int i = 1 ; i < N-1 ; i ++ )
        res = max( res , cnt[i-1] + cnt[i] + cnt[i+1] );
    cout << res;
    return 0;
}

D - Derangement

首先很容易证明的是,如果当前位置\(p_i=i\)无论向前向后交换都一定可以满足条件,这样我们只要一开始向着一个方向交换,就好了,最后就是特判一下最后一个位置。

#include <bits/stdc++.h>

using namespace std;

int32_t main() {
    ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
    int n , res = 0 ;
    cin >> n;
    vector<int> a( n+1 );
    for( int i = 1 ; i <= n ; i ++ )
        cin >> a[i];
    for( int i = 1 ; i < n ; i ++ )
        if( a[i] == i ) res ++ , swap( a[i] , a[i+1]);
    if( a[n] == n ) res ++;
    cout << res << "\n";
    return 0;
}

标签:AtCoder,cnt,072,cout,Beginner,int,res,cin,long
From: https://www.cnblogs.com/PHarr/p/17508735.html

相关文章

  • AtCoder Beginner Contest 238 Ex Removing People
    洛谷传送门AtCoder传送门考虑期望转计数,方案数显然是\(n!\)(第\(i\)次操作有\(n-i+1\)个人可供选择),所以问题转化为求所有方案的代价之和。考虑倒着做,变成先放一个人,然后依次放\(n-1\)个人,每次放的这个人可以让左边的人的\(S\)变成R,代价是他与他左边的人的距离,......
  • AtCoder Beginner Contest 307 Ex Marquee
    洛谷传送门AtCoder传送门一开始看错题了,看了好久才发现就是个板子。。。这个东西本质上是循环移位,我们考虑在\(S\)前后各添加\(W-1\)个.,例如\(W=5,S=\texttt{ABC}\)时,添加后\(S=\texttt{....ABC....}\)。此时我们发现\(S\)的每个长度为\(W\)的子串一一对......
  • AtCoder Beginner Contest(abc) 307
    A-WeeklyRecords题目大意小莫每天跑步,输入n周每天的步数,输出每周跑的总步数;解题思路签到题不多嗦了;神秘代码#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;intn,m,k,idx;signedmain(){ cin>>n; intsum=0; for(inti......
  • AtCoder Beginner Contest 307 G Approximate Equalization
    洛谷传送门AtCoder传送门考虑我们如果确定了最终态\(B=(B_1,B_2,...,B_n)\),如何计算最少操作次数。显然从左往右依次使\(A_i=B_i\)。当操作到第\(i\)个位置时,此时\(A'_i=\sum\limits_{j=1}^iA_j-B_j\),所需操作次数为\(|A'_i|\)。令\(C_i=\sum\limits_{......
  • AtCoder Beginner Contest 245 Ex Product Modulo 2
    洛谷传送门AtCoder传送门很好的题。下文令\(k\)为原题面中的\(n\),\(n\)为原题面中的\(k\),\(m\)为原题面中的\(m\)。从一些简单的情况入手。1.\(m\)为质数\(k=0\)的情况是平凡的,只需要要求\(\existsi\in[1,n],a_i=0\)即可。总方案数减去不合法方案数,......
  • AtCoder Beginner Contest 307 ABCDE
    AtCoderBeginnerContest307A-WeeklyRecordsProblemStatement题意:告诉你有几个礼拜,问你每个礼拜走的路程和。Solution思路:按题意模拟,每7天加起来就行。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;intmain(){ intn; cin>>n; llsum=......
  • AtCoder Beginner Contest 267 ABCDE
    AtCoderBeginnerContest267A-SaturdayProblemStatement题意:问你给定的天到礼拜六还要几天。思路:直接算。#include<bits/stdc++.h>usingnamespacestd;intmain(){ strings; cin>>s; if(s=="Monday")cout<<6-1<<endl; elseif(s=="Tues......
  • AtCoder Beginner Contest 252 Ex K-th beautiful Necklace
    洛谷传送门AtCoder传送门不知道为什么可以想到设\(n_c\)为颜色\(c\)的出现次数,那么\(\prodn_c\)也即选的方案数\(\approx1.25\times10^{11}\)。发现\(B=\sqrt{\prodn_c}\)不大,考虑meet-in-the-middle,把所有颜色分成两部分,每一部分的\(\prodn_c\)都接近\(......
  • Wallys/wifi 6 router ipq8072 enterprise wireless dual band /support wifi6e card.
    DR8072V01isanetworkingrouterpcbabasedonQualcommIPQ8072Acommunicationprocessor,withtwo10GbEinterfaces,onethroughanSFPcageandtheotherthroughanRJ45connector,plusfourGigabitEthernetports,and4×4MIMOWiFi6connectivity.Bas......
  • AtCoder Beginner Contest 212(E,F)
    AtCoderBeginnerContest212(E,F)E(dp)E题目大意为有\(n\)个点,我们需要找到\(k+1\)个点,用数组\(A\)表示,其中,\(A_i\)和\(A_{i+1}\)也不能一模一样,而且,规定\(A_0\)是\(1\),并且\(A_k\)也是\(1\),而且,还要满足下面的\(m\)种条边是不可以代表为\(A_i\)和\(A_{i+1}\),问我们可以......