CodeForces div3 第一场
题意: 对于一个数操作n次,操作如下: 如果末尾是0就将这个数除以10, 如果末尾不是0就将这个数-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 = 1e5+;
int main(){
///Fopen;
int n, k;
scanf("%d%d", &n, &k);
while(k--){
int t = n%;
if(t) n--;
else n/=;
}
printf("%d", n);
return ;
}
题意:求2个连续字符出现次数最多的那2个字符。
代码:
#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 cnt[N][N];
char str[N];
int main(){
///Fopen;
int n;
scanf("%d", &n);
scanf("%s", str);
int ans = -, s1, s2;
for(int i = ; i < n-; i++){
int x = str[i]-'A';
int y = str[i+]-'A';
cnt[x][y]++;
if(cnt[x][y] > ans){
ans = cnt[x][y];
s1 = x;
s2 = y;
}
}
printf("%c%c",s1+'A',s2+'A');
return ;
}
题意:给你一个数组, 要求找到一个数在[1,1e9]之间,使得恰好有k个数小于等于他,如果没有输出-1, 有就输出任意一个合法答案。
题解:sort一下数组, 如果第k个数等于第k+1个数就找不到一个数满足题意了。 还有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 = 2e5+;
int n, m;
int A[N];
int main(){
///Fopen;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++)
scanf("%d", &A[i]);
sort(A+, A++n);
if(m == ){
if(A[] == ) printf("-1");
else printf("");
}
else if(m == n){
printf("%d", (int)1e9);
}
else{
if(A[m] == A[m+]) printf("-1");
else printf("%d", A[m]);
}
return ;
}
D Divide by three, multiply by two
题意:将题目给的数重新排列,使得前一个数是后一个数的3倍,或者后一个数是前一个数2倍的情况最多。
题解:这个特殊的数列是不可能形成一个环的。DFS找一下就可以了,从长的开始输出。(也有更简单的方法, 但是当时写了DFS就DFS了。。。)
代码:
#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 = 1e2+;
int n, m;
LL A[N];
int cnt[N];
LL ans[N];
map<LL,int> mp;
void dfs(LL u){
cnt[mp[u]] = ;
if(u% == && mp.count(u/)){
if(cnt[mp[u/]] == -)
dfs(u/);
cnt[mp[u]] = max(cnt[mp[u]],+cnt[mp[u/]]);
}
if(mp.count(u*)){
if(cnt[mp[u*]] == -)
dfs(u*);
cnt[mp[u]] = max(cnt[mp[u]],+cnt[mp[u*]]);
}
}
void Show(LL u, int h){
printf("%I64d ", u);
A[mp[u]] = ;
h--;
if(h == ) return ;
if(u% == && mp.count(u/) && cnt[mp[u/]] == h && A[mp[u/]] != )
Show(u/,h); else if(mp.count(u*)
&& A[mp[u*]] !=
&& cnt[mp[u*]] == h){
Show(u*,h);
}
}
int main(){
scanf("%d", &n);
memset(cnt, -, sizeof(cnt));
for(int i = ; i <= n; i++){
scanf("%I64d", &A[i]);
mp[A[i]] = i;
}
for(int i = ; i <= n; i++){
if(cnt[i] == -){
dfs(A[i]);
} }
while(){
int Max = , save;
for(int i = ; i <= n; i++){
if(cnt[i] >= Max && A[i] != )
Max = cnt[i], save = i;
}
if(Max == ) break;
Show(A[save], Max);
}
return ;
}
题意:求环的个数, 这个环需要这个环上的点都只有2条边。
题解:DFS一下, 从某个点出发, 如果按照一个方向走能回到该点, 并且路上的点都只有2条边, 就cnt++;
代码:
#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+;
vector<int> son[*N];
int vis[N*];
int cnt = ;
void dfs(int u, int l, int v){
if(u == v){cnt++; return ;}
if(vis[v]) return ;
vis[v] = ;
if(son[v].size() == ){
if(l == son[v][]) dfs(u,v, son[v][]);
else dfs(u,v,son[v][]);
}
}
int main(){
///Fopen;
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++){
int u, v;
scanf("%d%d", &u, &v);
son[u].pb(v);
son[v].pb(u);
}
for(int i = ; i <= n; i++){
if(!vis[i]) {
vis[i] = ;
if(son[i].size() == ){
dfs(i, i, son[i][]);
}
}
}
printf("%d", cnt);
return ;
}
题意:求最长的递增子序列。 这个序列的前一项与后一项相差为1。
题解:开一个map, 映射一下某个值上一次访问的位置,然后每次处理一个新的点, 如果比这个点小1的值的mp不为0, 就将这个点的位置指向上一个比他小1的点,记录长度, 如果没有比他小1的点, 就指向-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 = 2e5+;
map<int,int> mp;
int cnt[N];
int pre[N];
int A[N];
int Max = , B = ;
void Show(int u){
if(u == -) return;
Show(pre[u]);
printf("%d ", u);
}
int main(){
///Fopen;
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &A[i]);
for(int i = ; i <= n; i++){
int t = A[i]-;
if(mp.count(t)){
pre[i] = mp[t];
cnt[i] = cnt[pre[i]]+;
}
else pre[i] = -, cnt[i] = ;
if(Max < cnt[i]){
Max = cnt[i];
B = i;
}
mp[A[i]] = i;
}
printf("%d\n", cnt[B]);
Show(B);
return ;
}
CodeForces div3 第一场的更多相关文章
- 2019年湖南多校第一场||2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)
第一场多校就打的这么惨,只能说自己太菜了,还需继续努力啊- 题目链接: GYM链接:https://codeforces.com/gym/101933 CSU链接:http://acm.csu.edu ...
- 校省选赛第一场C题解Practice
比赛时间只有两个小时,我没有选做这题,因为当时看样例也看不懂,比较烦恼. 后来发现,该题对输入输出要求很低.远远没有昨天我在做的A题的麻烦,赛后认真看了一下就明白了,写了一下,一次就AC了,没问题,真 ...
- 校省选赛第一场A题Cinema题解
今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...
- 计蒜之道 初赛第一场B 阿里天池的新任务(简单)
阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displ ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)
Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...
- 2018牛客暑期ACM多校训练营第一场(有坑未填)
(重新组队后的第一场组队赛 也是和自己队友的一次磨合吧 这场比赛真的算是一个下马威吧……队友上手一看 啊这不是莫队嘛 然后开敲 敲完提交发现t了 在改完了若干个坑点后还是依然t(真是一个悲伤的故事)然 ...
- 比赛总结——牛客网 NOIP赛前集训营提高组模拟第一场
第一场打的很惨淡啊 t1二分+前缀最小值没想出来,20分的暴力也挂了,只有10分 t2数位dp,调了半天,结果因为忘了判0的特殊情况WA了一个点,亏死 t3emmmm.. 不会 imone说是DSU ...
- NOI.AC NOIP模拟赛 第一场 补记
NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ...
随机推荐
- CountDownLatch实现多线程并发请求
package com.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Dat ...
- HDP Hive性能调优
(官方文档翻译整理及总结) 一.优化数据仓库 ① Hive LLAP 是一项接近实时结果查询的技术,可用于BI工具以及网络看板的应用,能够将数据仓库的查询时间缩短到15秒之内,这样的查询称之为Int ...
- SpringMVC学习笔记之---简单入门
SpringMVC简单入门 (一)什么是MVC设计模式 (1)model:模型数据,业务逻辑 (3)view:呈现模型,与用户进行交互 (3)controller:负责接收并处理请求,响应客户端 (二 ...
- Docker笔记(七):常用服务安装——Nginx、MySql、Redis
开发中经常需要安装一些常用的服务软件,如Nginx.MySql.Redis等,如果按照普通的安装方法,一般都相对比较繁琐 —— 要经过下载软件或源码包,编译安装,配置,启动等步骤,使用 Docker ...
- Idea搭建Spring+SpringMvc+Mybatis框架集成项目
1.新建maven项目 2.创建多模块 每个模块配置如父模块一样,除视图层 (视图层配置) 最后 common-通过模块,不依赖任何模块,有各种项目所需要用到的工具类 model- POJO.VO.D ...
- XAMPP/LAMPP到底在哪里启用APACHE2的rewrite
XAMPP/LAMPP是一套我们在个人建站过程中非常便捷常用的集成环境.特别是对于学习PHP开发和建站非常便捷. 最近在使用CentOS7环境下的XAMPP过程中,遇到了一个问题,也就是apache2 ...
- 记一次JPA遇到的奇葩错误——本地sql不识别表名的别名
记一次JPA遇到的奇葩错误——本地sql不识别表名的别名 报错:Unknown column 'our' in 'field list' 起因:需要本地sql查询后,分页返回自定义对象.报错信息如下: ...
- 8.12 day31 进程间通信 Queue队列使用 生产者消费者模型 线程理论 创建及对象属性方法 线程互斥锁 守护线程
进程补充 进程通信 要想实现进程间通信,可以用管道或者队列 队列比管道更好用(队列自带管道和锁) 管道和队列的共同特点:数据只有一份,取完就没了 无法重复获取用一份数据 队列特点:先进先出 堆栈特点: ...
- 100天搞定机器学习|day43 几张GIF理解K-均值聚类原理
前文推荐 如何正确使用「K均值聚类」? KMeans算法是典型的基于距离的聚类算法,采用距离作为相似性的评价指标,即认为两个对象的距离越近,其相似度就越大.该算法认为簇是由距离靠近的对象组成的,因此把 ...
- R 包 rgl 安装失败, 报错 X11 not found but required, configure aborted 及解决方法
R 包 rgl 安装失败, X11 not found but required, configure aborted * installing *source* package ‘rgl’ ... ...