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. MySQL通过binlog日志恢复数据

    一.查看下自己的MySQL是否开启了binlog日志 # 是否启用binlog日志 OFF:关闭 ON:开启 show variables like 'log_bin'; 二.开启binlog日志 在 ...

  2. Codeforces Round #792 (Div. 1 + Div. 2) A-E

    Codeforces Round #792 (Div. 1 + Div. 2) A-E A 题目 https://codeforces.com/contest/1684/problem/A 题解 思路 ...

  3. 虚拟机启动时报’A start job is running for /etc/rc.local .. Compatibility错误。

    虚拟机启动时报'A start job is running for /etc/rc.local .. Compatibility错误. 问题已经存在很长时间了,但是不影响ssh登录,遂置之未理. 经 ...

  4. Tapdata “设擂招贤”携手 LeetCode 举办全球极客技术竞赛

      2021年11月28日 Tapdata 专场全球极客技术竞赛将在 LeetCode 平台开赛,面向程序员"设擂招贤",打擂成功的前50名挑战者将优先获得 Tapdata 高端技 ...

  5. 【cartographer_ros】五: 发布和订阅陀螺仪Imu信息

    上一节介绍了里程计Odometry传感数据的订阅和发布. 本节会介绍陀螺仪Imu数据的发布和订阅.陀螺仪在cartographer中主要用于前端位置预估和后端优化. 目录 1:sensor_msgs/ ...

  6. PostgreSQL的查询技巧: 零除, GENERATED STORED, COUNT DISTINCT, JOIN和数组LIKE

    零除的处理 用NULLIF(col, 0)可以避免复杂的WHEN...CASE判断, 例如 ROUND(COUNT(view_50.amount_in)::NUMERIC / NULLIF(COUNT ...

  7. dolphinscheduler添加hana支持

    dolphinscheduler添加hana支持 转载请注明出处: https://www.cnblogs.com/funnyzpc/p/16395092.html 前面 上一节有讲datax对han ...

  8. testNG框架,使用@BeforeClass标注的代码,执行失败不抛出异常,只提示test ignore的解决方法

    郁闷了好久的一个问题,排错调试的时候是真滴麻烦... Google一圈,发现是testNG的Bug,升级testNG>=6.9.5,就能解决.

  9. Windows 进程的创建和终止

    创建一个进程 总述 如图,创建一个进程主要分为两部分,用户态部分和内核部分. 既然我们想看看一个进程是怎么被创建的,那我们就用 WinDbg 来看看从用户态到内核态都调用了什么: 第一步:我们先看看 ...

  10. day08 集合API | 遍历_ | 泛型 |增强For循环

    集合(续) 集合间的操作 集合提供了如取并集,删交集,判断包含子集等操作 package collection; import java.util.ArrayList; import java.uti ...