首页 > 其他分享 >Acwing.第134场周赛

Acwing.第134场周赛

时间:2023-12-16 22:15:12浏览次数:31  
标签:std 周赛 dist int ans 134 push Acwing

Acwing.第134场周赛

比赛地址

A排序

题目

思路:

简单的模拟

代码:

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	
	int ans=a+b+c;
	int maxn=max(a,max(b,c));
	int minn=min(a,min(b,c));

	cout<<minn<<" "<<ans-maxn-minn<<" "<<maxn<<endl;

}
int main(){

	int t=1;
	while(t--){
		solve();
	}
	return 0;

}

B 中等计算

题目链接

思路:

展开一下找个规律就好了,具体的可以看wift大佬的详细思路

代码:

#include<bits/stdc++.h>
using namespace std;
int b[1000005];
int main(){
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)b[i]=b[i-1]^i;//预处理
    int s=n%2?2:1;
    for(;s<n;s+=2)ans^=s;
    for(int i=2;i<=n;i++){
        int j=n-i+1;
        if(j%i==0&&j/i%2==0)continue;
        ans^=b[j%i-1];//被省了
        if(j/i%2)ans^=b[i-1];//被省了
    }
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        ans^=x;   
    }
    cout<<ans;
    return 0;
}

C建立新边

题目链接

思路:

我们可以对s点和t点都求一下跟所有点的最短路,之后我们在考虑新建的边对s到t最短路的影响,由于是无向边,所以我们要考虑两个方向

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1100;
const int INF=0x3f3f3f3f;

bool st[N][N];
int dist[2][N];
int n,m,s,t;
int ans;

std::vector<int> g[N];
void dfs(int x){
    int sd=s;
    if(x==1){
        sd=t;

    }
    queue<int> q;
    q.push(sd);
    for(int i=1;i<=n;i++){
        dist[x][i]=INF;
    }
    dist[x][sd]=0;
    while(q.size()){
        int y=q.front();
        q.pop();
        for(auto i:g[y]){
            if(dist[x][i]>dist[x][y]+1){
                dist[x][i]=dist[x][y]+1;
                q.push(i);

            }
        }
    }
}
void solve(){
    // int n,m,s,t;
    cin>>n>>m>>s>>t;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        st[x][y]=st[y][x]=true;
        //无向边
        g[x].push_back(y);
        g[y].push_back(x);

    }
    for(int i=0;i<2;i++){
        dfs(i);
    }
    int dist1=dist[0][t];

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(st[i][j]){
                continue;
            }
            if(dist[0][i]+dist[1][j]+1<dist1||dist[0][j]+dist[1][i]+1<dist1){
                continue;
            }
            ans++;

        }
    }
    cout<<ans<<endl;
    return ;


}

signed main(){
    int t=1;
    while(t--){
        solve();
    }
    return 0;

}

标签:std,周赛,dist,int,ans,134,push,Acwing
From: https://www.cnblogs.com/du463/p/17908442.html

相关文章

  • Acwing秋季每日一题补题---搜索字符串
    搜索字符串题目链接思路:字符串哈希+滑动窗口当然因为符合题意的子串会重复,所以我们要考虑去重的问题代码:#include<bits/stdc++.h>usingnamespacestd;#defineintunsignedlonglongconstintN=2e5+10;constintP=131;chara[N],b[N];//字符串intcnt[26];//统......
  • ACwing343.排序
    1.Floyd写法:#include<cstring>#include<iostream>#include<algorithm>usingnamespacestd;constintN=26;intn,m;boold[N][N];boolst[N];intcheck(){for(inti=0;i<n;i++)if(d[i][i])re......
  • 第 375 场周赛(滑动窗口,区间合并)
     使用差分的思想进行解决classSolution:defcountTestedDevices(self,batteryPercentages:List[int])->int:diff=0forxinbatteryPercentages:ifx>diff:diff+=1returndiff    clas......
  • 二分——acwing算法基础课笔记
    个人笔记,欢迎补充、指正。此次完全以个人理解来写。整数二分 整数二分有两种,分别是找左边界和找右边界。 寻找符合要求的左边界:绿色点intbsearch_1(intl,intr){while(l<r){intmid=l+r>>1;//对应下界,最左if(check(mid))r=......
  • Acwing 840. 模拟散列表
    题面:维护一个集合,支持如下几种操作:Ix,插入一个整数 \(x\);Qx,询问整数 \(x\) 是否在集合中出现过现在要进行 \(N\) 次操作,对于每个询问操作输出对应的结果。原题链接:840.模拟散列表-AcWing题库哈希表[1]基本概念哈希表也叫散列表,通过将键映射到索引位置(在关键......
  • AcWing 802. 区间和
    题面:假定有一个无限长的数轴,数轴上每个坐标上的数都是\(0\)。现在,我们首先进行\(n\)次操作,每次操作将某一位置\(x\)上的数加\(c\)。接下来,进行\(m\)次询问,每个询问包含两个整数\(l\)和\(r\),求出在区间\([l,r]\)之间的所有数的和。原题链接:802.区间和-AcW......
  • 59AcWing 840. 模拟散列表
    点击查看代码#include<iostream>#include<cstring>usingnamespacestd;constintN=200003,null=0x3f3f3f3f;inth[N];intfind(intx){intk=(x%N+N)%N;//索引while(h[k]!=null&&h[k]!=x){k++;if(k==N)k=0;//重新搜索......
  • Acwing 5367. 不合群数
    题面:如果一个正整数无法被 \([2,a]\) 范围内的任何整数整除,则称其为不合群数。请你计算并输出 \([2,b]\) 范围内的最大不合群数。提示:\(10\) 亿内的最大质数是 \(999999937\),且相邻质数之间的差值均不超过 \(300\)原题链接:5367.不合群数-AcWing根据给出的提示判......
  • AcWing 1205. 买不到的数目
    题面:水果糖被包成\(n\)颗一包和\(m\)颗一包的两种,用这两种包装来组合,不能拆包卖。在\(4\)颗一包和\(7\)颗一包的情况下,最大不能买到的数量是\(17\)。本题的要求就是在已知两个包装的数量时,求最大不能组合出的数字。原题链接:1205.买不到的数目-AcWing数论:组合......
  • ACwing342. 道路与航线
    这道题是把拓扑排序和迪杰斯特拉交叉进行。#include<iostream>#include<stdio.h>#include<algorithm>#include<cstring>#include<queue>#include<vector>usingnamespacestd;typedefpair<int,int>PII;constintN=25005,M=50......