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

AtCoder Beginner Contest 331

时间:2023-12-04 19:13:02浏览次数:29  
标签:AtCoder Beginner int 331 cin long solve ans define

AtCoder Beginner Contest 331

这场状态好差,下午的校赛也打的好差。

A - Tomorrow

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

void solve(){
    int M,D;
    int y,m,d;
    cin>>M>>D>>y>>m>>d;
    d++;
    if(d>D){
        m++;
        d=1;
    }
    if(m>M){
        y++;
        m=1;
    }
    cout<<y<<" "<<m<<" "<<d;
}

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

B - Buy One Carton of Milk

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

void solve(){
    int n;
    cin>>n;
    int a,b,c;
    cin>>a>>b>>c;
    int ans=99999999999;
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
            for(int k=0;k<20;k++){
                if(6*i+8*j+k*12>=n) ans=min(ans,a*i+j*b+k*c);
            }
        }
    }
    cout<<ans<<endl;
}

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

C - Sum of Numbers Greater Than Me

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

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

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++) pre[i] = pre[i-1] + b[i];
    for(int i=1;i<=n;i++){
        int idx=upper_bound(b+1,b+1+n,a[i])-b;
        cout<<pre[n]-pre[idx-1]<<" ";
    }
}

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

D - Tile Pattern

写的时候感觉这道题好狗屎,就没打了放弃了。

本来以为是我的想法挺粪的,看了下佬的码发现大家 写的其实都挺粪的。

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

int P[5010][5010];
int n,q;

void solve(){
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            char c;
            cin>>c;
            P[i][j]=(c=='B');
        }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            P[i][j] += P[i-1][j] + P[i][j-1] - P[i-1][j-1];
    while(q--){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int len=c-a+1;
        int wid=d-b+1;
        a%=n,b%=n,c%=n,d%=n;
        a++,b++,c++,d++;
        if(a > 1) len += a - 1;
		if(c < n) len += n - c;
		if(b > 1) wid += b - 1;
		if(d < n) wid += n - d;
		int ans=0;
        ans += P[a - 1][n] * (wid / n);
		ans += (P[n][n] - P[c][n]) * (wid / n);
		ans += P[n][b - 1] * (len / n);
		ans += (P[n][n] - P[n][d]) * (len / n);
		ans -= P[a - 1][b - 1];
		ans -= P[n][b - 1] - P[c][b - 1];
		ans -= P[a - 1][n] - P[a - 1][d];
		ans -= P[n][n] + P[c][d] - P[c][n] - P[n][d];
		ans  = P[n][n] * (len / n) * (wid / n) - ans;
		cout << ans << endl;
    }
}

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

E - Set Meal

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

struct node{
    int x,y;
    int val;
    friend bool operator <(node a,node b){
        return a.val<b.val;
    }
};
const int N = 1e5 + 10;
set<int> path[N];

void solve(){
    int n,m,l;
    cin>>n>>m>>l;
    vector<pair<int,int>> a,b;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        a.push_back({x,i});
    }
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        b.push_back({x,i});
    }
    for(int i=1;i<=l;i++){
        int u,v;
        cin>>u>>v;
        path[u].insert(v);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    priority_queue<node> que;
    que.push({n-1,m-1,a[n-1].first+b[m-1].first});
    set<pair<int,int>> vis;
    vis.insert({n-1,m-1});
    while(que.size()){
        node u=que.top();
        que.pop();
        int aa=a[u.x].second;
        int bb=b[u.y].second;
        if(path[aa].find(bb)==path[aa].end()){
            cout<<u.val<<endl;
            return;
        }
        if(u.x>=0&&u.y-1>=0&&!vis.count({u.x,u.y-1}))
        {
            que.push({u.x,u.y-1,a[u.x].first+b[u.y-1].first});
            vis.insert({u.x,u.y-1});
        }
        if(u.x-1>=0&&u.y>=0&&!vis.count({u.x-1,u.y}))
        {
            que.push({u.x-1,u.y,a[u.x-1].first+b[u.y].first});
            vis.insert({u.x-1,u.y});
        }
    }
}

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

F - Palindrome Query

线段树下次再补吧

标签:AtCoder,Beginner,int,331,cin,long,solve,ans,define
From: https://www.cnblogs.com/zfxyyy/p/17875703.html

相关文章

  • 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......
  • AtCoder Beginner Contest 331
    B-BuyOneCartonofMilk难度:⭐题目大意选择有三种套餐,6个鸡蛋S元,8个鸡蛋M元,12个鸡蛋L元;问如果要买至少N个鸡蛋,最少花费多少钱;解题思路一道入门级dp;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false......
  • 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......
  • ABC331G题解
    ABC331G日常被bot吊打罢了。首先注意到一件事是你需要求一堆max的期望对吧。所以其实上来就应该试试上min-max容斥的。但是鉴于我没有脑子,所以其实没想到也可以理解。先来复习一下式子:\[Emax(S)=\sum_{T\subsetS}Emin(T)(-1)^{\midT\mid-1}\]所以带入要求的东西......
  • 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;}......
  • ABC 331 F - Palindrome Query(字符串哈希,树状数组)
    字符串哈希[OI-Wiki](字符串哈希-OIWiki(oi-wiki.org))分为两种哈希方式:以左为高位和以右为高位如果只是快速查询每个字串的哈希值,用以左为高位比较简单,即\[Hash[l...r]=Hash[1...r]-Hash[1...(l-1)]\timesbase^{r-l+1}\]但是如果有修改操作,需要将每一位的Hash值存......
  • AtCoder_abc326
    T12UP3DOWN简单的if判断,做题一分钟,翻译十分钟。。。代码:#include<bits/stdc++.h>usingnamespacestd;intmain(){ intx,y;cin>>x>>y; if((x<=y&&y-x<=2)||(x>y&&x-y<=3)) cout<<"Yes"; elsecout<<"No&......
  • AtCoder_abc327
    T1ab循环从s[0]到s[n-2]判断有无ab相邻T2A^A两层循环枚举就可以了由于aa会增长的很快,所以当a=16时aa就已经大于$10^{18}$了,一定不会T就这么点数打表也能过T3NumberPlace就是数独的判断规则,h,l,g三个数组存储已有的数就好宫的判断我用了一个三维数组前两个维度表示宫的......
  • AtCoder_abc329
    AtCoder_abc329比赛链接A-SpreadA题链接题目大意输入一个字符串由大写字母组成的$S$,输出$S$并在每一个字符之间加上空格解题思路随便打打就能过.jpg代码//Problem:A-Spread//Contest:AtCoder-SkyInc,ProgrammingContest2023(AtCoderBeginnerContest329)//......
  • AtCoder_abc330
    AtCoder_abc330比赛链接A-CountingPassesA题链接题目大意给出$N$个数$a_1,a_2,a_3\cdots,a_N$,和一个正整数$L$。输出有几个$a_i\leL$.解题思路O(n)遍历一遍就好了代码//Problem:A-CountingPasses//Contest:AtCoder-TOYOTASYSTEMSProgrammingContest20......