SDUT 2022 Autumn Team Contest 7th
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的更多相关文章
- C++ 与 Visual Studio 2022 和 WSL(五)——WSL2
Build and Debug C++ with WSL 2 Distributions and Visual Studio 2022 References Build and Debug C++ w ...
- atcoder beginner contest 251(D-E)
Tasks - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)\ D - At Most 3 (Contestant ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- codeforces 360 C
C - NP-Hard Problem Description Recently, Pari and Arya did some research about NP-Hard problems and ...
- C - NP-Hard Problem
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- CF687A. NP-Hard Problem[二分图判定]
A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 360 C - NP-Hard Problem
原题: Description Recently, Pari and Arya did some research about NP-Hard problems and they found the ...
- CodeForces 534D Program B
Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) ...
- 【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 ...
随机推荐
- ES5的继承和ES6的继承有什么区别?让Babel来告诉你
如果以前问我ES5的继承和ES6的继承有什么区别,我一定会自信的说没有区别,不过是语法糖而已,充其量也就是写法有区别,但是现在我会假装思考一下,然后说虽然只是语法糖,但也是有点小区别的,那么具体有什么 ...
- 019(The XOR Largest Pair)(字典树)
题目:http://ybt.ssoier.cn:8088/problem_show.php?pid=1472 题目思路:异或是啥呀? 异或就是把两个数字变成位数相同的二进制在同位比较,相同为0,不同为 ...
- 以脚本形式运行python库
技术背景 当我们尝试运行python的帮助文档时,会看到如下这样的一个说明: $ python3 -h usage: python3 [option] ... [-c cmd | -m mod | f ...
- 如何学习Vim
如果你是Linux用户,学习Vim会有很大的好处. 如果你是windows用户,个人建议还是使用vscode. 准备大约40min的学习时间,打开终端,输入下面命令开启自带教程 vimtutor 按操 ...
- mybatis-拦截器实际应用-替换表名-2022新项目
一.业务场景 考虑到新项目中部分与业务数据相关的表在后期数据量会比较大,架构师在最开始设计项目中与业务数据相关的表时,就已经考虑使用分表来 进行处理,给业务数据相关的每张表都添加统一批次的后缀,查询这 ...
- 2022-7-25 第七组 pan小堂 多态
多态 多态是继封装.继承之后,面向对象的第三大特性. 现实事物经常会体现出多种形态,如学生,学生是人的一种,则一个具体的同学张三既是学生也是人,即出现两种形态. Java作为面向对象的语言,同样可以描 ...
- 体验Lambda的更优写法和Lambda标准格式
体验Lambda的更优写法 借助Java8的全新语法,上述Runnable接口的匿名内部类写法可以通过更简单的Lambda表达式达到等效: public class Lambda02 { public ...
- DateFormat类的format方法和parse方法
/** * 使用DateFormat类中的方法format,把日期格式化为文本 * String format(Date date) 按照指定的模式把Date日期格式化为符合模式的字符串 * 使用步骤 ...
- CF Round #805 (Div. 3) 题解
A 直接模拟即可,注意 \(10^k\) 的情况(罚时!罚时!罚时!). A Code using namespace std; typedef long long ll; typedef pair& ...
- Java学习 (九)基础篇 包机制&JavaDoc
包机制 为了更好地组织类,Java提供了包机制,用于区别类名的命名空间 包语句的语法为: package pkg[.pkg2[.pkg3...]]; 一般利用公司域名倒置作为包名:com.feng.x ...