Codeforces Round #595 (Div. 3) A,B,C,D
A题:n个学生,分成任意组,要求每组中任意两名学生的技能值相差不等于1,问最小分组.
#include<bits/stdc++.h> using namespace std; #define int long long
int arr[];
signed main(){
int _;
cin>>_;
while(_--){
int n;
cin>>n;
for(int i=;i<=n;i++)
cin>>arr[i];
sort(arr+,arr++n);
int sum=;
int flag=;
for(int i=;i<n;i++){
if(arr[i+]-arr[i]==){
flag=;
break;
}
}
if(flag){
printf("2\n");
}else{
printf("1\n");
}
}
return ;
}
/* */
B1题:
题意:n个学生,每个学生有单独的一本书,每天学生 i 会把 书给 ai,问每个学生重新拿到自己的书经过的天数。
思路:一发暴力水过
#include<bits/stdc++.h> using namespace std;
#define int long long
int arr[];
int ans[];
signed main(){
int _;
cin>>_;
while(_--){
int n;
cin>>n;
for(int i=;i<=n;i++)
scanf("%lld",&arr[i]);
for(int i=;i<=n;i++){
int sum=;
int temp=i;
while(){
sum++;
if(arr[temp]==i){
break;
}
temp=arr[temp];
}
ans[i]=sum;
}
for(int i=;i<=n;i++){
printf("%lld ",ans[i]);
}
printf("\n");
}
return ;
}
B2:
找环,只要在同一个环的天数相等。开始暴力。。。。。。。。。。。
#include<bits/stdc++.h> using namespace std;
#define int long long
#define N 200020
int arr[N];
int ans[N];
int vis[N];
int a[N];
signed main(){
int _;
cin>>_;
while(_--){
int n;
scanf("%lld",&n);
for(int i=;i<=n;i++){
scanf("%lld",&arr[i]);
vis[i]=;
} for(int i=;i<=n;i++){
int sum=;
if(vis[i])
continue;
int temp=i;
vector<int> v;
while(){
sum++;
if(arr[temp]==i){
break;
}
temp=arr[temp];
v.push_back(temp);
}
vis[i]=sum;
for(int j=;j<v.size();j++){
vis[v[j]]=sum;
}
// vis[i]=sum;
}
for(int i=;i<=n;i++){
printf("%lld ",vis[i]);
}
printf("\n");
}
return ;
}
/* 3 6
1 3 4 9 10
1 2 3 4 5
5 1 2 4 3
4 4 4 1 4
*/
C1:
题意:求大于n的m,m有不同的3的次幂。
想到进制,即可知道符合的数字3进制转换后只有1和0. 暴力一下。
#include<bits/stdc++.h> using namespace std;
#define int long long
int ans[]; signed main(){ int _;cin>>_;
while(_--){
int n;
scanf("%lld",&n);
if(n==){
cout<<""<<endl;continue;
}
if(n==){
cout<<<<endl;continue;
}
int i=n;
for(;;i++){
int temp=i;
int flag=;
while(temp){
int x=temp%;
if(x!=&&x!=){
flag=;
break;
}
temp/=;
}
if(flag){
cout<<i<<endl;
break;
}
}
}
return ;
}
C2:
思路:从左到右,找到第一个2的位置,然后开始模拟进位。第一个2后面的数全改为0。调了好久的BUG。
/*
10212121111
11000000000
110121212211
111000000000
11212211221
10000000000
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
int fpow(int a,int b){
int res=;
while(b){
if(b%){
res*=a;
}
a*=a;
b/=;
}
return res;
}
signed main(){
int _;cin>>_;
while(_--){
int n;
cin>>n;
vector<int> v;
int temp;
temp=n;
while(temp){
v.push_back(temp%);
temp/=;
}
int flag1=-;
int flag2=;
int cnt=;
/*
for(int i=v.size()-1;i>=0;i--){ }
cout<<endl;
*/
for(int i=v.size()-;i>=;i--){
if(v[i]==){
flag1=i;
break;
}
if(v[i]==){
flag2=i;
}
}
if(flag1==-){
cout<<n<<endl;
continue;
}
if(!flag2){
int x=v.size();
cout<<fpow(,x)<<endl;
continue;
}else{
int ans[];
int cnt=;
for(int i=v.size()-;i>=;i--)
ans[i]=v[i];
int j;
for( j=flag1;j<v.size();j++){ if(ans[j]==){
ans[j]=;
ans[j+]=ans[j+]+;
}
}/*
for(int i=v.size()-1;i>=0;i--){
cout<<v[i]<<" ";
}
cout<<endl;
for(int i=0;i<j;i++){
cout<<ans[i]<<" ";
}
cout<<endl;*/
int X=;
// cout<<j<<" "<<endl;
for(int i=j-;;i--){
if(i<=flag1){
break;
}
if(ans[i])
X+=fpow(,i);
// cout<<fpow(3,i)<<" ";
}
cout<<X<<endl;
}
}
return ;
}
【补题...................................】
D1,D2题:
题意:给出n个线段,要求同一个点不能有超过k条线段覆盖。求最少要删多少条线段。
思路:r从小到大排序。r相等的时候l从小到大排序。然后进行区间的最值和区间修改。用线段树维护。
然后在网上找了一个板子 套了一下。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional> #define l(x) t[x].l
#define r(x) t[x].r
#define dat(x) t[x].dat
#define sum(x) t[x].sum
#define add(x) t[x].add
#define clean(x, y) memset(x, y, sizeof(x))
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f;
typedef long long LL;
using namespace std; template <typename T>
inline void read(T &s) {
s = ;
T w = , ch = getchar();
while (!isdigit(ch)) { if (ch == '-') w = -; ch = getchar(); }
while (isdigit(ch)) { s = (s << ) + (s << ) + (ch ^ ); ch = getchar(); }
s *= w;
} template<typename T>
inline void write(T s) {
if (s < ) putchar('-'), s = -s;
if (s > ) write(s / );
putchar(s % + '');
} int n;
int a[maxn];
struct tree {
int l, r;
LL dat, sum, add;
} t[maxn << ]; void build(int p, int l, int r) {
l(p) = l, r(p) = r;
if (l == r) { sum(p) = a[l]; return ; }
int mid = (l + r) >> ;
build(p << , l, mid);
build(p << | , mid + , r);
dat(p) = dat(p << ) + dat(p << | );
// sum(p) = sum(p << 1) + sum(p << 1 | 1);
} void spread(int p) {
if (add(p)) {
// sum(p << 1) = add(p) * (r(p << 1) - l(p << 1) + 1);
// sum(p << 1 | 1) = add(p) * (r(p << 1 | 1) - l(p << 1 | 1) + 1);
add(p << ) += add(p);
add(p << | ) += add(p);
dat(p << ) += add(p);
dat(p << | ) += add(p);
add(p) = ;
}
} void change(int p, int l, int r, int d) {
if (l <= l(p) && r >= r(p)) {
sum(p) += (LL) d * (r(p) - l(p) + );
add(p) += d;
dat(p) += d;
return ;
}
spread(p);
int mid = (l(p) + r(p)) >> ;
if (l <= mid) change(p << , l, r, d);
if (r > mid) change(p << | , l, r, d);
sum(p) = sum(p << ) + sum(p << | );
dat(p) = max(dat(p << ), dat(p << | ));
} LL ask(int p, int l, int r) {
if (l <= l(p) && r >= r(p)) return dat(p);
spread(p);
int mid = (l(p) + r(p)) >> ;
LL val = ;
if (l <= mid) val = max(val, ask(p << , l, r));
if (r > mid) val = max(val, ask(p << | , l, r));
return val;
} int main() {
read(n);
build(, , n);
for (int i = ; i <= n; ++i) {
int opt, x, y;
read(opt), read(x), read(y);
if (opt == )
change(, x, y, );
else{
int T=ask(, x, y);
write(T); putchar('\n');
}
}
return ;
}
E题待补。
Codeforces Round #595 (Div. 3) A,B,C,D的更多相关文章
- Codeforces Round #595 (Div. 3)D1D2 贪心 STL
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
- Codeforces Round #595 (Div. 3)B2 简单的dfs
原题 https://codeforces.com/contest/1249/problem/B2 这道题一开始给的数组相当于地图的路标,我们只需对每个没走过的点进行dfs即可 #include &l ...
- Codeforces Round #595 (Div. 3) D2Too Many Segments,线段树
题意:给n个线段,每个线段会覆盖一些点,求删最少的线段,使得每个点覆盖的线段不超过k条. 思路:按右端点排序,之后依次加入每个线段,查询线段覆盖区间内的每个点,覆盖的最大线段数量,如果不超过k,那就可 ...
- Codeforces Round #595 (Div. 3)
A - Yet Another Dividing into Teams 题意:n个不同数,分尽可能少的组,要求组内没有两个人的差恰为1. 题解:奇偶分组. int a[200005]; void te ...
- Codeforces Round #595 (Div. 3) 题解
前言 大家都在洛谷上去找原题吧,洛谷还是不错的qwq A 因为没有重复的数,我们只要将数据排序,比较两两之间有没有\(a_j - a_i == 1 (j > i)\) 的,有则输出 \(2\) ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- quartz 简单定时器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- 有关Linux服务器的一些配置
1.Redis部署 1.版本 redis-3.0.72.上传解压 3.编译 make && make install 问题:/bin/sh: cc: command not found ...
- Idea中一个服务按多个端口同时启动
1.勾选并行启动 2.-Dserver.port=9018
- 通过pip命令导出和导入Python环境安装包
我们在开发完代码后,一般需要将依赖包导出,然后在移植到其他系统使去安装,保证环境正常 导出Python环境安装包[root@bogon ~]# pip freeze > packages.t ...
- 为什么用JS取不到cookie的值?解决方法如下!
注意:cookie是基于域名来储存的.要放到测试服务器上或者本地localhost服务器上才会生效.cookie具有不同域名下储存不可共享的特性.单纯的本地一个html页面打开是无效的. 明明在浏览中 ...
- Codeforces 1245 E. Hyakugoku and Ladders
传送门 显然这个图是个 $DAG$ ,那么就可以考虑跑 $dp$ 了 先考虑没有梯子的情况,首先把每个位置标号,越后面的位置编号越小,终点位置编号为 $1$ 那么从终点往起点 $dp$ ,枚举当前位置 ...
- Mish:一个新的SOTA激活函数,ReLU的继任者
Mish:一个新的SOTA激活函数,ReLU的继任者 CVer 昨天 以下文章来源于AI公园 ,作者ronghuaiyang AI公园 专注分享干货的AI公众号,图像处理,NLP,深度学习,机器学 ...
- Spring Boot Redis 分布式缓存的使用
一.pom 依赖 <!-- 分布式缓存 --> <dependency> <groupId>org.springframework.boot</groupId ...
- SQL递归查询(with as)
SQL递归查询(with cte as) with cte as( select Id,Pid,DeptName,0 as lvl from Department where Id = 2 ...
- Seaborn(二)之数据集分布可视化
Seaborn(二)之数据集分布可视化 当处理一个数据集的时候,我们经常会想要先看看特征变量是如何分布的.这会让我们对数据特征有个很好的初始认识,同时也会影响后续数据分析以及特征工程的方法.本篇将会介 ...