1.J题:给你T组数据,每一组数据给你一个区间,让你求这个区间的范围,区间的起始时间和终止时间可能被包含或重复

    思路:思路的话,就是直接把给定的两个区间的之间的数包括端点存到vector去重,然后直接输出个数即可,或者直接存到set里直接系统去重也可

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; vector<int> ans; int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--)
{
int a,b;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
ans.push_back(i);
}
}
sort(ans.begin(),ans.end());
ans.erase(unique(ans.begin(),ans.end()),ans.end());
cout<<ans.size()<<endl;
return 0;
}

2.L题:给你T个数让你求每个数的非质因数的因数个数

思路:一开始我们想到的是直接预处理,直接在前面预处理出来答案,然后按O(1)的时间复杂度查询就可以了,但是其实这样的话再做预处理的时候就会超时,然后我们知道了怎么算因数的个数,根据惟一分解定理我们可以知道,每一个数都可以被分成几个质数的几次方相乘的乘积,然后把每一个数的指数加一,然后乘起来就是因数的个数,此时我们把质因数的个数去掉之后,就可以得到非质因数的个数。然后我们可以直接去求质因数,这样的话及可以求出每一个质因数的个数(及指数)又可以求出质因数的个数,这样的话我们就可以求出最终的答案,但是直接这样写的话还是会超时,因为它有3e6次的询问,但是我们最大的数才是2e6所以有的数肯定不止被算了一遍,这样的话我们可以记录一下,如果这个数被算过的话我们就直接输出,没有被算过的时候再进行计算

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int N = 3e6 + 10;
int res[N]; void divide(int x)
{
int k=x;
int ans=1;
int ans2=0;
for (int i = 2; i <= x / i; i ++ )
if (x % i == 0)
{
int s = 0;
while (x % i == 0)
{
x /= i, s ++ ;
}
ans*=s+1;
if(x!=1)
ans2++;
}
if (x > 1) ans*=2;
printf("%d\n",ans-ans2-1);
res[k]=ans-ans2-1;
} int main()
{
res[1]=1;
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
if(res[n]!=0)
printf("%d\n",res[n]);
else
divide(n);
}
return 0;
}

3.B题:意思是一开始给我们一张图,然后其中有一台主机会被病毒给侵染,但是我们想让它一次就把所有的主机感染,并且我们会加上一些边保证能一次感染,问我们加边的条数最少是多少,病毒只可以隔一个侵染。

思路:翟老板全程提供思路,此题其实我们如果想让它在只侵染一台主机的情况下,想要把所有的机器都通过跳跃的毒素侵染的话,我们首先至少得把所有的点全部连在一起,这样的话我们可以用并查集,通过并查集我们可以求出一共有几个图,我们首先要把不连在一起的图连在一起,这样的话我们就会有ans=父节点等于其本身的点的个数减一。然后我们再考虑,光连同还不行,必须要存在一个奇数环,这样的话才能保证在只侵染一个主机的前提下,主机通过病毒去侵染别的主机进而侵染全部,然后奇数环的话我们可以联想到二分图,二分图就是没有奇数环的无向图,这样的话我们只需要通过染色法判断它是否是个二分图即可,如果是二分图的话,我们就要加上一条边(及凑出奇数环),如果不是二分图的话,说明我存在奇数环,最后直接输出ans即可。

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int N = 1e6 + 10;
int p[N];
int e[N],ne[N],h[N],color[N],idx; void add(int a,int b)
{
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
} int find(int x)
{
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
} bool dfs(int u,int c)
{
color[u]=c; for(int i=h[u];~i;i=ne[i])
{
int j=e[i];
if(!color[j])
{
if(!dfs(j,3-c))
return false;
}
else if(color[j]==c)
{
return false;
}
}
return true;
} int main()
{
int ans=0;
memset(h,-1,sizeof h);
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) p[i]=i;
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
add(a,b);
add(b,a);
int pa=find(a);
int pb=find(b);
p[pa]=pb;
}
for(int i=1;i<=n;i++)
{
if(p[i]==i)
ans++;
}
ans=ans-1;
bool flag=true;
for(int i=1;i<=n;i++)
{
if(!color[i])
{
if(!dfs(i,1))
{
flag=false;
break;
}
}
}
if(flag==true)
{
ans++;
}
printf("%d\n",ans);
return 0;
}

SDUT 2022 Autumn Team Contest 7th的更多相关文章

  1. C++ 与 Visual Studio 2022 和 WSL(五)——WSL2

    Build and Debug C++ with WSL 2 Distributions and Visual Studio 2022 References Build and Debug C++ w ...

  2. atcoder beginner contest 251(D-E)

    Tasks - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)\ D - At Most 3 (Contestant ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. codeforces 360 C

    C - NP-Hard Problem Description Recently, Pari and Arya did some research about NP-Hard problems and ...

  5. C - NP-Hard Problem

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  6. CF687A. NP-Hard Problem[二分图判定]

    A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. codeforces 360 C - NP-Hard Problem

    原题: Description Recently, Pari and Arya did some research about NP-Hard problems and they found the  ...

  8. CodeForces 534D Program B

    Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) ...

  9. 【CF39E】【博弈论】What Has Dirichlet Got to Do with That?

    Description You all know the Dirichlet principle, the point of which is that if n boxes have no less ...

随机推荐

  1. Cron表达式(七子表达式)

    一.七子含义 秒 分 时 日 月 周 年 可用的值 0~59 0~59 0~23 1~31 112(JANDEC) 17(SUNSAT) 1970~2099 可用的通配符 , - * / , - * ...

  2. Codeforces Round #804 (Div. 2)

    题目链接 A  The Third Three Number Problem 题意 给你一个n,让你求满足的a,b,c. 如果不存在则输出-1. 思路 显然任意a,b,c是不可能得到奇数. 只考虑偶数 ...

  3. Intel的CPU系列说明

    至强可扩展系列是英特尔推出的新一代至强处理器系列,如今距离该系列推出几乎过去一年了.新的CPU并没有延续E系列的命名,英特尔将至强可扩展系列以金属命名,将该系列分为"铂金Platinum&q ...

  4. Identity Server 4资源拥有者密码认证控制访问API

    基于上一篇文章中的代码进行继续延伸,只需要小小的改动即可,不明白的地方可以先看看本人上一篇文章及源码: Identity Server 4客户端认证控制访问API 一.QuickStartIdenti ...

  5. 手机APP无法抓包HTTPS解决方案

    问题表现:某个APP的HTTPS流量抓取不到,Fiddler报错,但可以正常抓取其它的HTTPS流量 可能原因: 1.Flutter应用,解决方案:https://www.cnblogs.com/lu ...

  6. 线程池ThreadPoolExector核心ctl, execute, addWorker, reject源码分析

    线程池核心方法execute()解析: public void execute(Runnable command) {//#1 if (command == null) throw new NullP ...

  7. 网络营销谁在行?PHP小哥打个样

    PHP -ゞ 阿白同学的学习笔记 PHP学习笔记 - 01 - web2.0 - 网络营销 @ 目录 一. 前言 二. 开始(借助菜鸟教程平台练习) 1. Hello World -- 第一个案例 2 ...

  8. 【高并发】通过源码深度分析线程池中Worker线程的执行流程

    大家好,我是冰河~~ 在<高并发之--通过ThreadPoolExecutor类的源码深度解析线程池执行任务的核心流程>一文中我们深度分析了线程池执行任务的核心流程,在ThreadPool ...

  9. Mybatis的使用(2)

    1 :模糊查询 #{}占位符和¥{}的区别 #{}占位符:传参大部分用#{}传参,它的底层是PreparedStatement对象,是安全的数据库访问,它能够防止sql注入 1.1:如果parmete ...

  10. 8月份的.NET Conf 活动 专注于 .NET MAUI

    .NET Conf:Focus on MAUI 是一个为期一天的免费直播活动,将于太平洋时间 8 月 9 日上午 9 点开始,来自社区和 Microsoft 团队的演讲者们将分享使用MAUI .了解. ...