这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平。(我也不清楚)。

A. Remove Duplicates

题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
int vis[N];
int a[N];
int main(){
///Fopen;
int n;
int t = ;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
if(vis[a[i]] == ) t++;
vis[a[i]] = i;
}
printf("%d\n", t);
for(int i = ; i <= n; i++){
if(vis[a[i]] == i){
printf("%d ", a[i]);
}
}
return ;
}

B. File Name

题意:不能有3个或以上的x连续出现,求删除几个x之后,不会有3个连续的x出现。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
char str[N];
int main(){
///Fopen;
int n;
scanf("%d", &n);
scanf("%s", str);
str[n] = '.';
int cnt = ;
int ans = ;
for(int i = ; i <= n; i++){
if(str[i] == 'x') cnt++;
else {
if(cnt >= ) ans += cnt - ;
cnt = ;
}
}
printf("%d", ans);
return ;
}

C. Letters

题意:这里有n个宿舍(楼),每个宿舍有a[i]个人,现在有m封信要寄过来,没有名字, 只有从第一个宿舍开始计数的第a[i]个人的信息, 求每封信对应的宿舍和第几个人。

题解:前缀和, 然后lowbound查找一下编号为b[i]的人, 转化信息一下就好了。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 2e5+;
int n, m;
LL a[N];
LL sum[N];
int main(){
///Fopen;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++){
scanf("%I64d", &a[i]);
sum[i] = sum[i-] + a[i];
}
while(m--){
LL tmp;
scanf("%I64d", &tmp);
int pos = lower_bound(sum+,sum++n,tmp) - sum;
printf("%d %I64d\n",pos, tmp - sum[pos-]);
}
return ;
}

D. Almost Arithmetic Progression

题意:给你一个数列, 可以将这将这个数列的任意一个元素加一,减一或者不改变, 求形成等差数列之后改变元素的次数最小, 如果没有办法形成等差数列, 就输出-1。

题解:看着很复杂, 但是如果第1个元素和第2个元素定下来了之后, 那么后面的元素都定下来了, 所以暴力枚举9种情况, 然后check一遍, 找到答案。

题解:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
int a[N];
int b[N]; int n;
int ans = INF;
int check(int u){
int cnt = ;
for(int i = ; i <= n; i++){
b[i] = b[i-] + u;
if(abs(a[i]-b[i]) > ) return -;
if(abs(a[i]-b[i]) == ) cnt++;
}
return cnt;
}
int d1[]={,,-};
int d2[]={,,-};
int main(){
///Fopen; scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
if(n == || n == ){
printf("");
return ;
}
for(int i = ; i < ; i++)
for(int j = ; j < ; j++){
b[] = a[] + d1[i];
b[] = a[] + d2[j];
int tmp = check(b[]-b[]);
if(tmp != -){
ans = min(ans, tmp+(i!=)+(j!=));
}
}
if(ans == INF) printf("-1");
else printf("%d", ans);
return ;
}

E. Bus Video System

题意:这里有一辆bus, 然后有n个站, 最多容纳m个人,每一个站都会有人上车下车,求始发点人数可能的情况数, 如果没办法就矛盾就输出0。

题解:记录下这辆车在车上最多多少人, 最少的时候多少人。 然后 通过最多人数 算出始发点 最多能有多少人, 通过最少的人数算出始发点最少多少人。 然后就得出答案了。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
int n, m;
int main(){
///Fopen;
scanf("%d%d", &n, &m);
int l = , r = ;
int tmp = , t;
while(n--){
scanf("%d", &t);
tmp += t;
r = min(r, tmp);
l = max(l, tmp);
}
int maxn = m - l;
int minn = -r;
int ans = maxn-minn+;
if(ans <= ) ans = ;
printf("%d\n", ans);
return ;
}

F. Mentors

题意:有n个人, 每一个人有一个能力值, 然后求这个能力值高的人能当能力值低的人的导师,然后又m对人在吵架, 如果2个人吵架, 他们2个人就不能组成导师关系, 现在求每个人可以当多少个人的导师数目。

题解:map记录一下能力值, 然后 在用另一个map 对第一个map求前缀和, 然后映射出每个人可以当多少个人的导师数目, 然后对于吵架的人, 2方谁能力值高谁的数目就-1, 就可以得到答案了。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 2e5+;
int n, k;
int a[N];
int cnt[N];
map<int,int> mp;
map<int,int> mmp;
int main(){
///Fopen;
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
mp[a[i]]++;
}
int tmp = ;
map<int,int>::iterator it = mp.begin();
while(it!=mp.end()){
mmp[it->fi] = tmp;
tmp += it->second;
it++;
}
for(int i = ; i <= n; i++){
cnt[i] = mmp[a[i]];
}
int u, v;
while(k--){
scanf("%d%d", &u, &v);
if(a[u] > a[v])cnt[u]--;
else if(a[u] < a[v]) cnt[v]--;
}
for(int i = ; i <= n; i++){
printf("%d%c",cnt[i]," \n"[i==n]);
}
return ;
}

G. Petya's Exams

题意: Petyas有m门考试, 每一门考试有个s,d, c, 他只能在s,d-1之间复习这门科目并且要复习c天, 然后第d天要考试, Petays一天只能干一件事情, 求怎么样安排Petyas的时间使得Petya能通过所有考试的n天日程安排, 如果不行输出-1。

题解:贪心, 先安排考试时间早的, 如果有一门考试安排不下了, 就输出-1.

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e3+;
int n, m;
struct Node{
int s, d, c;
int id; }A[N];
int vis[N];
bool cmp(Node x, Node y){
return x.d < y.d;
}
int main(){
///Fopen;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++){
scanf("%d%d%d", &A[i].s, &A[i].d, &A[i].c);
vis[A[i].d] = m+;
A[i].id = i;
}
sort(A+, A++m, cmp);
for(int i = ; i <= m; i++){
int cnt = ;
for(int j = A[i].s; j < A[i].d; j++){
if(!vis[j]){
cnt++;
vis[j] = A[i].id;
if(cnt == A[i].c) break;
}
}
if(cnt != A[i].c) {printf("-1"); return ;}
}
for(int i = ; i <= n; i++)
printf("%d%c", vis[i], " \n"[i==n]);
return ;
}

CodeForces Round#480 div3 第2场的更多相关文章

  1. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  2. Codeforces Round #412 Div. 2 第一场翻水水

    大半夜呆在机房做题,我只感觉智商严重下降,今天我脑子可能不太正常 A. Is it rated? time limit per test 2 seconds memory limit per test ...

  3. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  4. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  5. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  6. CodeForces Round #527 (Div3) C. Prefixes and Suffixes

    http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...

  7. CodeForces Round #527 (Div3) A. Uniform String

    http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...

  8. Codeforces Round #480 (Div. 2)980C Posterized+分组类贪心

    传送门:http://codeforces.com/contest/980/problem/C 参考 题意:给定n个数字,每个数在0~256间,现在给至多连续k的数分为一组,给出字典序最小的答案. 思 ...

  9. Codeforces Round #480 (Div. 2) C - Posterized

    题目地址:http://codeforces.com/contest/980/problem/C 官方题解: 题解:一共256个像素网格,可以把这个256个分组,每个分组大小<=k.给出n个像素 ...

随机推荐

  1. codeforces 340 A. The Wall

    水水的一道题,只需要找xy的最小公倍数,然后找a b区间有多少个可以被xy的最小公倍数整除的数,就是答案. //============================================ ...

  2. Go“一个包含nil指针的接口不是nil接口”踩坑

    最近在项目中踩了一个深坑--"Golang中一个包含nil指针的接口不是nil接口",总结下分享出来,如果你不是很理解这句话,那推荐认真看下下面的示例代码,避免以后写代码时踩坑. ...

  3. 基于http(s)协议的模板化爬虫设计

    声明:本文为原创,转载请注明出处 本文总共三章,前面两章废话吐槽比较多,想看结果的话,直接看第三章(后续会更新,最近忙着毕设呢,毕设也是我自己做的,关于射频卡的,有时间我也放上来,哈哈). 一,系统总 ...

  4. Java 8原生API也可以开发响应式代码?

    前段时间工作上比较忙,这篇文章一直没来得及写,本文是阅读<Java8实战>的时候,了解到Java 8里已经提供了一个异步非阻塞的接口(CompletableFuture),可以实现简单的响 ...

  5. 新手的java学习建议

    前言 进入IT领域,就像进入大海—浩瀚而广阔.然而,它又很容易让人迷茫,不知所措.所以,在IT的海洋中,找好一艘船特别重要,这艘船带你前进.减少迷失.这艘船或许是一个人,或一本书,又或许是一篇文章. ...

  6. Netty学习(五)-DelimiterBasedFrameDecoder

    上一节我们说了LineBasedframeDecoder来解决粘包拆包的问题,TCP以流的方式进行数据传输,上层应用协议为了对消息进行区分,一般采用如下4种方式: 消息长度固定,累计读取到消息长度总和 ...

  7. golang 结合实例更好的理解参数传递和指针

    关于参数传递 其实go的参数传递,核心就是一句话:go里所有参数传递都是值传递,既把参数复制一份放到函数里去用. go的函数传参,不管参数是什么类型,都会复制一份,然后新的参数在函数内部被使用. 不像 ...

  8. Spark 系列(九)—— Spark SQL 之 Structured API

    一.创建DataFrame和Dataset 1.1 创建DataFrame Spark 中所有功能的入口点是 SparkSession,可以使用 SparkSession.builder() 创建.创 ...

  9. Python装饰器完全解读

    1 引言 装饰器(Decorators)可能是Python中最难掌握的概念之一了,也是最具Pythonic特色的技巧,深入理解并应用装饰器,你会更加感慨——人生苦短,我用Python. 2 初步理解装 ...

  10. 前端小知识-html5

    一.伪类与伪元素 为什么css要引入伪元素和伪类:是为了格式化文档树以外的信息,也就是说,伪类和伪元素是用来修饰不在文档树中的部分 伪类用于当已有元素处于的某个状态时,为其添加对应的样式,这个状态是根 ...