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的更多相关文章

  1. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  2. Codeforces Round #595 (Div. 3)B2 简单的dfs

    原题 https://codeforces.com/contest/1249/problem/B2 这道题一开始给的数组相当于地图的路标,我们只需对每个没走过的点进行dfs即可 #include &l ...

  3. Codeforces Round #595 (Div. 3) D2Too Many Segments,线段树

    题意:给n个线段,每个线段会覆盖一些点,求删最少的线段,使得每个点覆盖的线段不超过k条. 思路:按右端点排序,之后依次加入每个线段,查询线段覆盖区间内的每个点,覆盖的最大线段数量,如果不超过k,那就可 ...

  4. Codeforces Round #595 (Div. 3)

    A - Yet Another Dividing into Teams 题意:n个不同数,分尽可能少的组,要求组内没有两个人的差恰为1. 题解:奇偶分组. int a[200005]; void te ...

  5. Codeforces Round #595 (Div. 3) 题解

    前言 大家都在洛谷上去找原题吧,洛谷还是不错的qwq A 因为没有重复的数,我们只要将数据排序,比较两两之间有没有\(a_j - a_i == 1 (j > i)\) 的,有则输出 \(2\) ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. MEAN: AngularJS + NodeJS的REST API开发教程

    Node.JS https://www.jdon.com/idea/nodejs/web-app-with-angularjs-and-rest-api-with-node.html Mean是一个热 ...

  2. python将url转变成二维码图片

    将url数据转变成二维码数据,再将二维码图片转成base64格式返回 import qrcode import io def url_image(self,url): img = qrcode.mak ...

  3. WUSTOJ 1246: 字符串排序(Java)

    1246: 字符串排序 题目   输入n(n<100)个字符串,每个字符串长度不超过1000,将他们按字典顺序输出.更过内容点击标题. 分析   Java中的ArrayList()可以比较方便的 ...

  4. asp.net core-6.Bind读取配置文件到C#实例中

    1,创建asp.net core web应用程序,选择空网站 2,创建一个appsettings.json文件 为什么要叫appsettings.json呢?因为在Iwebhost启动的时候没有添加任 ...

  5. asp.net core-5.控制台读取json文件

    1,创建控制台应用程序,应用using Microsoft.Extensions.Configuration; 2,新建一个app.json文件 然后修改app.json的属性 3,生成项目,可以看到 ...

  6. hdu 2647 还是逆向拓扑

    Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he ...

  7. SQL logic error no such module: fts5 解决方案

    因项目原因,需要使用SQLite的全文索引,用到了最新的fts5模块 但在咱们.net framwork中却会提示“SQL logic error no such module: fts5”:找不到f ...

  8. docker 学习1 WSL docker ,Windows docker

    获取Linux内核版本 //使用 lsb_release -a 可见我电脑上的 WSL Linux 版本是 Ubuntu的. 安装docker for ubuntu (遇到问题) 转[http://b ...

  9. el-table——可合并单元格的表格

    <el-table v-loading="loading" :data="tableData" border :span-method="col ...

  10. Flutter——BottomNavigationBar组件(底部导航栏组件)

    BottomNavigationBar常用的属性: 属性名 说明 items List<BottomNavigationBarItem> 底部导航条按钮集合 iconSize icon c ...