这次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. ubuntu清理系统垃圾与备份

    虽然linux下不会有windows下的那么多垃圾和磁盘碎片!但还是会留下一些用不着的临时文件或是多次升级后的N个旧的内核! 1,非常有用的清理命令: sudo apt-get autoclean s ...

  2. 改 Anaconda Jupyter Notebook 开发文件保存目录

    1.打开cmd,输入命令找到配置文件路径 jupyter notebook --generate-config 2.打开 jupyter_notebook_config.py 修改配置 c.Noteb ...

  3. 案例实战:每日上亿请求量的电商系统,JVM年轻代垃圾回收参数如何优化?

    出自:http://1t.click/7TJ 目录: 案例背景引入 特殊的电商大促场景 抗住大促的瞬时压力需要几台机器? 大促高峰期订单系统的内存使用模型估算 内存到底该如何分配? 新生代垃圾回收优化 ...

  4. 【Java笔记】【Java核心技术卷1】chapter3 D3数据类型

    package chapter3; public class D3数据类型 { public static void main(String[] arg) { //Java 整型(字节数不会随硬件变化 ...

  5. JNDI----数据连接池

    JNDI:提供了查找和访问各种命名和目录服务的通用,统一的接口 常用的配置属性:   name:表示以后要查找的名称.通过此名称可以找到DataSource,此名称任意更换,但是程序中最终要查找的就是 ...

  6. azure k8s netcore 程序初次部署

    以下都是我在2018年12月份做的实验,今天才发布出来. 念想 首先是了解一些关于K8s的一些基础概念,推荐查看一下这个链接,非常适合入门k8s.是因为K8S的环境搭建比较复杂(最主要是懒),其实也有 ...

  7. 通过Blazor使用C#开发SPA单页面应用程序(1)

    2019年9月23——25日 .NET Core 3.0即将在.NET Conf上发布! .NET Core的发布及成熟重燃了.net程序员的热情和希望,一些.net大咖也在积极的为推动.NET Co ...

  8. (二十三)c#Winform自定义控件-等待窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  9. python骚操作---Print函数用法

    ---恢复内容开始--- python骚操作---Print函数用法 在 Python 中,print 可以打印所有变量数据,包括自定义类型. 在 3.x 中是个内置函数,并且拥有更丰富的功能. 参数 ...

  10. Yii 三表关联 角色表、角色权限连接表、权限表

    Yii 三表关联 角色表.角色权限连接表.权限表 角色表 role----------------id 唯一序号name 角色名称---------------- 角色权限连接表 lp-------- ...