首页 > 其他分享 >[Educational Codeforces Round 159 (Rated for Div. 2)](https://codeforces.com/contest/1902)

[Educational Codeforces Round 159 (Rated for Div. 2)](https://codeforces.com/contest/1902)

时间:2023-12-04 21:12:16浏览次数:52  
标签:Educational Rated return contest int long -- solve define

Educational Codeforces Round 159 (Rated for Div. 2)

好困,差点没打

A - Binary Imbalance

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve() {
	string s;
	int n;
	cin>>n;
	cin>>s;
	if(n==1&&s[0]=='0'){
        cout<<"YES"<<endl;
        return;
	}
	for(int i=1;i<s.size();i++){
        if(!(s[i]==s[i-1]&&s[i]=='1')){
            cout<<"YES"<<endl;
            return;
        }
	}
	cout<<"NO"<<endl;
}

signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
	return 0;
}

B - Getting Points

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

int n,P,l,t;

void solve() {
    cin>>n>>P>>l>>t;
    int all=(n+6)/7;
    int day=(all+1)/2;
    if(all*t+day*l>=P){
        int ans=(P+(2*t+l-1))/(2*t+l);
        cout<<n-ans<<endl;
        return;
    }
    int ans=day;
    P-=all*t+day*l;
    cout<<n-ans-(P+l-1)/l<<endl;
}

signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
	return 0;
}

C - Insert and Equalize

(好像写复杂了)

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 2e5 + 10;
int a[N];
int n;

void solve() {
    cin>>n;
    map<int,int> b;
    for(int i=1;i<=n;i++) cin>>a[i],b[a[i]]++;
    sort(a+1,a+1+n);
    if(n==1){
        cout<<1<<endl;
        return;
    }
    int x;
    if(n==2){
        x=a[2]-a[1];
    }else{
        x=__gcd(a[2]-a[1],a[3]-a[2]);
        for(int i=4;i<=n;i++) x=__gcd(x,a[i]-a[i-1]);
    }
    int ans1=0,ans2=0;
    int idx1=-1,idx2=a[n]+x;
    for(int i=a[n];;i-=x)
        if(b.find(i)==b.end()){
            idx1=i;
            break;
        }
    for(int i=1;i<=n;i++){
        ans1+=(a[n]-a[i])/x;
        ans2+=(idx2-a[i])/x;
    }
    ans1+=(a[n]-idx1)/x;
    cout<<min(ans1,ans2)<<endl;
}

signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
	return 0;
}

E - Collapsing Strings

打的时候有想着用字符串哈希正着求一遍,反着求一边。想了很久怎么快速求出答案,没想懂。

打完别人写的才懂怎么实现的。

搓了用map的hash wa21了,看了题解说是字符串哈希很容易被卡,用字典树维护数量好写一点。

调半天,刚开始全开ll,runtime error6,后面把宏定义注释掉了,又爆int了。

#include <bits/stdc++.h>
//#define int long long
#define endl '\n'
using namespace std;

const int N = 2e6 + 10;
int tr[N][26],cnt1[N],cnt2[N];
string s;
int n;
int tot;

int ct(int u,int v){
    if(!tr[u][v]) tr[u][v]=++tot;
    return tr[u][v];
}

void solve() {
    cin>>n;
    unsigned long long ans=0;
    for(int i=1;i<=n;i++){
        cin>>s;
        ans += s.size()*2*n;
        int u=0;
        for(int j=0;j<s.size();j++) u=ct(u,s[j]-'a'),cnt1[u]++;
        u=0;
        for(int j=s.size()-1;j>=0;j--) u=ct(u,s[j]-'a'),cnt2[u]++;
    }

    for(int i=1;i<=tot;i++) ans-= 2ll*cnt1[i]*cnt2[i]; //这里一定一定一定要是2ll*,不然会爆Int。
    cout<<ans<<endl;
}

signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--) solve();
	return 0;
}

D - Robot Queries

这题主要要搞清楚原路径上的点和 翻转后路径上的点 的映射关系

标签:Educational,Rated,return,contest,int,long,--,solve,define
From: https://www.cnblogs.com/zfxyyy/p/17875987.html

相关文章

  • AtCoder Beginner Contest 328
    AtCoderBeginnerContest328链接:ToyotaProgrammingContest2023#7(AtCoderBeginnerContest328)-AtCoderA题意:给定n个数,将小于等于x的数加起来输出。#include<bits/stdc++.h>#defineintlonglong#defineendl'\n';usingnamespacestd;voidsolve(){......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    EducationalCodeforcesRound158(RatedforDiv.2)AEDU的题总是感觉写起来怪怪的#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;inta[101];voidsolve(){intn,x;cin>>n>>x;intans=0;......
  • AtCoder Beginner Contest 331
    AtCoderBeginnerContest331这场状态好差,下午的校赛也打的好差。A-Tomorrow#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;voidsolve(){intM,D;inty,m,d;cin>>M>>D>>y>>m>&......
  • AtCoder Beginner Contest 331 G Collect Them All
    洛谷传送门AtCoder传送门设数字\(i\)第一次拿到的时间为\(t_i\),所求即为\(E(\max\limits_{i=1}^mt_i)\)。施min-max容斥,有:\[\begin{aligned}E(\max\limits_{i=1}^mt_i)&=\sum\limits_{T\subseteq[1,m]\landT\ne\varnothing}(-1)^{|T|-1}E(\min\l......
  • Educational Codeforces Round 159 (Rated for Div. 2)
    EducationalCodeforcesRound159(RatedforDiv.2)基本情况A题秒了。B题想出来贪心思想,也想出来怎么找最优解了,但实现极其复杂繁琐,最后以先超时优化后又错误的结果告终。B.GettingPoints明显越后面开始学收益越高。然后写了个简单粗暴的纯模拟,T了。#include<iostrea......
  • 2023-2024 CTU Open Contest
    A.Beth'sCookiesn=int(input())s=input()res=[]foriins:ifres==[]:res.append(i)elifi=='(':ifres[-1]==')':res.append("*")res.append(i)else:......
  • AtCoder Beginner Contest 331
    B-BuyOneCartonofMilk难度:⭐题目大意选择有三种套餐,6个鸡蛋S元,8个鸡蛋M元,12个鸡蛋L元;问如果要买至少N个鸡蛋,最少花费多少钱;解题思路一道入门级dp;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false......
  • The 13th Shandong ICPC Provincial Collegiate Programming Contest
    Preface昨天VP的那场没有字符串还没有原形毕露,今天遇到一个后期字符串直接和祁神大眼瞪小眼了最后一个半小时祁神狂冲F成功写出两个version的假算法,而我已经滚去补之前欠下的题目了赛后被徐神狠狠拷打了,评价为徐神是我们的红太阳,没有他我们都不能活A.Orders签到,按截止时间......
  • AtCoder Beginner Contest 295
    B-Bombs题意:就是说有一种炸弹,能炸曼哈顿距离的障碍物,要你打印出炸完后的图模拟#include<bits/stdc++.h>usingnamespacestd;charmp[50][50];voidsolve(){ intn,m; cin>>n>>m; for(inti=1;i<=n;i++){ for(intj=1;j<=m;j++){ cin>>mp[i][j]; } } for......
  • AtCoder Beginner Contest 326
    B-326-likeNumbers题意:找到一个不小于n的数是326数,定义是思路:简单的模拟循环即可#include<bits/stdc++.h>usingnamespacestd;boolcheck(intx){ vector<int>a; while(x){ a.push_back(x%10); x/=10; } if(a[1]*a[2]==a[0])returntrue; elsereturnfalse;}......