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个像素 ...
随机推荐
- tomcat配置启动文件
修改tomcat到指定文件夹 conf -> server.xml <Host name="localhost" appBase="webapps" ...
- JVM(二):画骨
### 概述 我们首先来认识一下`JVM`的运行时数据区域,如果说`JVM`是一个人,那么运行时数据区域就是这个人的骨架,它支撑着JVM的运行,所以我们先来学习一下运行时数据区域的分类和简单介绍. # ...
- 设计模式:与SpringMVC底层息息相关的适配器模式
目录 前言 适配器模式 1.定义 2.UML类图 3.实战例子 4.总结 SpringMVC底层的适配器模式 参考 前言 适配器模式是最为普遍的设计模式之一,它不仅广泛应用于代码开发,在日常生活里也很 ...
- 使用Yapi展示你的api接口
今天研究了下一款非常好用的api集中展示工具---Yapi,具体网址 https://hellosean1025.github.io/yapi/documents/index.html 如图,看下基本 ...
- 63342 接口 奇遇 IDEA
今天遇到一件很奇怪的事情,本来是想做一些手机页面看看效果,用IDEA 打搭建了一个静态页面网站,可是手机死活就是访问不了,网上的配置方法试过也没有用,其中包括这篇很详细博客: http://fanni ...
- 内存泄漏排查之:Show me your Memory
java 语言有个神奇的地方,那就是你时不时会去关注下内存.(当然了,任何牛逼的同学都应该关注内存) 今天我们就来这么场景吧:某应用运行了一段时间后,ecs监控报警了,内存比较高了,怎么办?随着时间的 ...
- input默认值设置
在input框里我们可以设置 一些默认值,在点击之后input之后就消失了 <input id="_le_name" type="text" onFocu ...
- 洛谷 P3628 特别行动队
洛谷题目页面传送门 题意见洛谷. 这题一看就是DP... 设\(dp_i\)表示前\(i\)个士兵的最大战斗力.显然,最终答案为\(dp_n\),DP边界为\(dp_0=0\),状态转移方程为\(dp ...
- golang 中获取字符串个数
golang 中获取字符串个数 在 golang 中不能直接用 len 函数来统计字符串长度,查看了下源码发现字符串是以 UTF-8 为格式存储的,说明 len 函数是取得包含 byte 的个数 // ...
- (三十二)c#Winform自定义控件-表格
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...