CodeForces Round#480 div3 第2场
这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平。(我也不清楚)。
题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素。
代码:
#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 ;
}
题意:不能有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 ;
}
题意:这里有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 ;
}
题意:这里有一辆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 ;
}
题意:有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 ;
}
题意: 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场的更多相关文章
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #412 Div. 2 第一场翻水水
大半夜呆在机房做题,我只感觉智商严重下降,今天我脑子可能不太正常 A. Is it rated? time limit per test 2 seconds memory limit per test ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #480 (Div. 2)980C Posterized+分组类贪心
传送门:http://codeforces.com/contest/980/problem/C 参考 题意:给定n个数字,每个数在0~256间,现在给至多连续k的数分为一组,给出字典序最小的答案. 思 ...
- Codeforces Round #480 (Div. 2) C - Posterized
题目地址:http://codeforces.com/contest/980/problem/C 官方题解: 题解:一共256个像素网格,可以把这个256个分组,每个分组大小<=k.给出n个像素 ...
随机推荐
- Find out "Who" and "Where"
Yesterday a friend of mine Kirby came to me with a smartphone and she wanted me to do her a favor. S ...
- mysql新增一列为主键
mysql新增一列为主键 由于一次疏忽在建表的时候忘记加上主键了, 但是目前来说表里面又有数据了,所以不能删表重建,所以需要新加一列主键 然后我就新加一列,并且为auto_increment,然后设置 ...
- 浅谈微服务架构与服务治理的Eureka和Dubbo
前言 本来计划周五+周末三天自驾游,谁知人算不如天算,周六恰逢台风来袭,湖州附近的景点全部关停,不得已只能周五玩完之后,于周六踩着台风的边缘逃回上海.周末过得如此艰难,这次就聊点务虚的话题,一是浅谈微 ...
- golang常用的http请求操作
之前用python写各种网络请求的时候写的非常顺手,但是当打算用golang写的时候才发现相对来说还是python的那种方式用的更加顺手,习惯golang的用法之后也就差别不大了,下面主要整理了常用的 ...
- Elasticsearch6.x和7.x版本常用插件汇总
elasticsearch插件汇总 基于es 7.3版本试用. 一.安全插件 1.x-pack a.介绍 包括安全(x-pack-security),监视(x-pack-watcher),警报(x-p ...
- python学习之并发编程(理论部分)
第一章 操作系统 管理控制协调计算机中硬件与软件的关系. 操作系统的作用? 第一个作用: 将一些对硬件操作的复杂丑陋的接口,变成简单美丽的接口. open函数. 第二个作用: 多个进程抢占一个(CPU ...
- Gitment评论插件的使用
前言 继上一篇的 GitPages部署自己的网站 现在开始添加博客的评论插件Gitment.这里的话我是使用hexo添加gitment插件,如果不是使用hexo,请到官网指定这里. 开始 第一步 注册 ...
- 自定义genericUDF demo
package cn.com.dtmobile.hiveUdf; import org.apache.hadoop.hive.ql.exec.UDFArgumentException; import ...
- random库的使用
一.random库介绍 random库是使用随机数的Python标准库 伪随机数:采用梅森旋转算法生成的(伪)随机序列中元素 random库主要用于生成随机数 使用random库:import ran ...
- 数据读写API——IO流
理清一些概念 1.Java 中的IO是干啥的? IO指的是Input和Output,主要目的是实现数据在存储介质之间的传输.[流:数据流,类比与水流的流动] 2.IO分类 按照操作单元来划分,可以分为 ...