这次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. 解决:django.db.utils.OperationalError: unable to open database file

    这是一个从GitHub上下载的,一个网站项目的源码.想要在自己的电脑上运行,期间过程相当曲折,不过至此终于是完成了. 1.安装过程: python2->virtualenv->django ...

  2. 有趣的Flex布局

    对于刚接触前端的小白,在还原页面样式的时候,往往会遇到页面布局(layout)上的问题,用着生硬的padding来固定盒子的位置,不仅代码看的沉重,还得适应各种浏览器页面,始终没有办法做到统一.接下来 ...

  3. python3 编译安装

    前言: Linux下大部分系统默认自带python2.x的版本,最常见的是python2.6或python2.7版本,默认的python被系统很多程序所依赖,比如centos下的yum就是python ...

  4. 用jquery实现放大镜效果

    ----css代码--- *{margin:0;padding:0;} .showimg{position:relative;width:450px;height:420px;border:1px s ...

  5. Caffeine Cache-高性能Java本地缓存组件

    前面刚说到Guava Cache,他的优点是封装了get,put操作:提供线程安全的缓存操作:提供过期策略:提供回收策略:缓存监控.当缓存的数据超过最大值时,使用LRU算法替换.这一篇我们将要谈到一个 ...

  6. LeetCode——409. Longest Palindrome

    题目: Given a string which consists of lowercase or uppercase letters, find the length of the longest ...

  7. struts的上传下载

    文件上传 添加jar包 commons-io-1.3.2.jar commons-fileupload-1.2.1.jar 前台页面 form表单 method值为post 添加"encty ...

  8. Promise对象的resolve回调函数和reject回调函数使用

    Promise是ES6中用来结局回调地狱的问题的但是并不能帮我们减少代码量 Promise是一个构造函数 new Promise() 得到一个Promise一个实例 在Promise上有两个函数分别是 ...

  9. Flink Metrics 源码解析

    Flink Metrics 有如下模块: Flink Metrics 源码解析 -- Flink-metrics-core Flink Metrics 源码解析 -- Flink-metrics-da ...

  10. javaScript基础-0 javascript概述

    一.简介 javaScript一种面向web的编程语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早 ...