先刷前四题,剩下的有空补。

792A New Bus Route

题意:给出x 轴上的n 个点,问两个点之间的最短距离是多少,有多少个最短距离。

思路:排序后遍历。

代码:

 #include<stdio.h>
#include<algorithm>
using namespace std;
#define N 200005
int w[N];
int main(){
int n;
while(~scanf("%d", &n)){
for(int i=; i<n; i++){
scanf("%d", &w[i]);
}
sort(w, w+n);
int mint=w[]-w[], co=;
for(int i=; i<n; i++){
if(w[i]-w[i-]<mint){
mint=w[i]-w[i-];
co=;
}
else if(w[i]-w[i-]==mint) co++;
}
printf("%d %d\n", mint, co);
}
return ;
}

792A AC代码

792B Counting-out Rhyme

题意:1-n n个数围成一圈,初始位置为1,有m 个操作,每个操作给一个整数x,表示前进x 步后删去当前位置的数,再前进一步,输出每次操作删除的数

思路:模拟,用pos表示当前位置,循环m 次。注意得到x 后先取余当前剩余数量。

代码:

 #include<stdio.h>

 int main(){
int n, m, x;
while(~scanf("%d%d", &n, &m)){
bool vis[]={}, flag=false;
int pos=, num=n;
while(m--){
scanf("%d", &x);
x=x%num;
while(x--){
do
{
pos++;
pos%=n;
}while(vis[pos]==);
}
if(flag) printf(" ");
flag=true;
printf("%d", pos+);
vis[pos]=;
do
{
pos++;
pos%=n;
}while(vis[pos]==);
num--;
}
printf("\n");
}
return ;
}

792B AC代码

792C Divide by Three

题意:给一个数,问最少删除多少位后可以被3 整除。

思路:

  有一个大数取余要先理解。用sum 保存所有位和取余3 的结果。

  如果sum==0,不需要删除;

  如果sum==1,有可能删除一位1(取余后),有可能删除两位2;

  如果sum==2,有可能删除一位2,有可能删除两位1。

  写一个函数del(char *s, int k)表示从s 里删除一个数字k 并且去除前导0。接着几个if、else判断一下就可以了。

代码:

 #include<stdio.h>
#include<string.h>
void del(char *s, int k){
int ls=strlen(s), i;
for(i=ls-; i>=; i--){
if((s[i]-'')%==k) break;
}
if(i==-) return ;
for(int j=i; j<ls; j++) s[j]=s[j+];
if(s[]==){
s[]='-';
s[]='';
s[]=;
return ;
}
for(i=; s[i]; i++){
if(s[i]!='') break;
}
if(s[i]==) s[]='', s[]=;
else{
for(int j=i; j<ls; j++){
s[j-i]=s[j];
}
}
}
char s[], ts[];
int main(){
while(~scanf("%s", s)){
int sum=;
for(int i=; s[i]; i++){
sum+=s[i]-'';
sum%=;
}
if(sum==) printf("%s\n", s);
else{
int n1=, n2=;
for(int i=; s[i]; i++){
if((s[i]-'')%==) n1++;
else if((s[i]-'')%==) n2++;
}
if(sum==){
if(n2<){
del(s, );
printf("%s\n", s);
}
else if(n1==){
del(s, );
del(s, );
printf("%s\n", s);
}
else{
strcpy(ts, s);
int ls1, ls2;
del(ts, );
ls1=strlen(ts);
del(s, );
del(s, );
ls2=strlen(s);
if(ls1>ls2) printf("%s\n", ts);
else printf("%s\n", s);
}
}
else{
if(n2==){
del(s, );
del(s, );
printf("%s\n", s);
}
else if(n1<){
del(s, );
printf("%s\n", s);
}
else{
strcpy(ts, s);
int ls1, ls2;
del(ts, );
del(ts, );
ls1=strlen(ts);
del(s, );
ls2=strlen(s);
if(ls1>ls2) printf("%s\n", ts);
else printf("%s\n", s);
}
}
}
}
return ;
}

792C AC代码

792D Paths in a Complete Binary Tree

题意:给一个n ,一个m ,n 表示有n 个结点的完整二叉树,m 表示m 个询问,每次询问给出初始结点编号和移动序列,问移动后的结点编号。(树结点编码依据中序遍历)

思路:

  预处理+模拟。

  可以先通过一个dfs找到初始位置的层数,这个dfs里面同时求出初始位置到根的路径(用于判断当前位置是父结点的左孩子或右孩子)。

  接着根据初始位置的层数,先预处理一下移动序列,把不合理的操作去掉。(简化后续操作难度)

  接着模拟当前位置变化即可。分三种情况处理即可(重点的子树结点数量可以通过当前层数求出)

代码:

 #include<stdio.h>
#define LL long long int getNum(LL n){
int ret=;
while(n){
n>>=;
ret++;
}
return ret;
} int dfs(LL l, LL r, LL p, bool *ss, int &ssp, int ceng){ // 确定初始位置的行
LL mid=(l+r)/;
if(mid==p) return ceng;
else if(mid>p){
ss[ceng]=;
ssp=ceng;
return dfs(l, mid-, p, ss, ssp, ceng+);
}
else{
ss[ceng]=;
ssp=ceng;
return dfs(mid+, r, p, ss, ssp, ceng+);
}
} void init(char *s, int rp, int num){
int j=;
for(int i=; s[i]; i++){
if(s[i]=='L' || s[i]=='R'){
if(rp==num);
else{
rp++;
s[j++]=s[i];
}
}
else{
if(rp==);
else{
rp--;
s[j++]=s[i];
}
}
}
s[j]=;
} LL dp[];
LL solve(char *s, bool *ss, int ssp, LL p, int rp, int num){
if(s[]==) return p;
if(s[]=='L'){
LL ln=dp[num-rp]-;
p=p-ln+(ln-)/;
rp++;
ss[++ssp]=;
}
else if(s[]=='R'){
LL rn=dp[num-rp]-;
p=p++(rn-)/;
rp++;
ss[++ssp]=;
}
else{
if(ss[ssp]==){
LL rn=dp[num-rp]-;
p=p++rn;
}
else{
LL ln=dp[num-rp]-;
p=p--ln;
}
ssp--;
rp--;
} return solve(s+, ss, ssp, p, rp, num);
} char s[];
bool ss[];
int main(){
dp[]=;
for(int i=; dp[i-]<=1e18; i++){
dp[i]=dp[i-]*;
}
LL n, p;
int m;
while(~scanf("%I64d%d", &n, &m)){
int num = getNum(n);
while(m--){
scanf("%I64d%s", &p, s);
int ssp=;
int rp = dfs(, n, p, ss, ssp, );
init(s, rp, num); printf("%I64d\n", solve(s, ss, ssp, p, rp, num));
}
}
return ;
}

792D AC代码

codeforces 792A-D的更多相关文章

  1. 3.26-3.31【cf补题+其他】

      计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), s ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  10. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. .net core自定义高性能的Web API服务网关

    网关对于服务起到一个统一控制处理的作用,也便于客户端更好的调用:通过网关可以灵活地控制服务应用接口负载,故障迁移,安全控制,监控跟踪和日志处理等.由于网关在性能和可靠性上都要求非常严格,所以针对业务需 ...

  2. 使用 ASP.NET Core MVC 创建 Web API(三)

    使用 ASP.NET Core MVC 创建 Web API 使用 ASP.NET Core MVC 创建 Web API(一) 使用 ASP.NET Core MVC 创建 Web API(二) 十 ...

  3. 微软开发者大会:VS 2019 Preview 发布;Windows UX 主要技术开源

    美国当地时间12月4日,微软正式举行 Microsoft Connect(); 2018 开发者大会,本次大会的 slogan 是"Build the apps of tomorrow, t ...

  4. 说说我为什么看好Spring Cloud Alibaba

    最近对<Spring Cloud Alibaba基础教程>系列的催更比较多,说一下最近的近况:因为打算Spring Boot 2.x一起更新.所以一直在改博客Spring Boot专题页和 ...

  5. 斑马打印机的安装调试,生成PDF

    1.  我使用的斑马打印机GK888T.有问题打客服,耐心等待.售后电话4006456456得到了解决. 2.  我遇到的问题是打印一张之后指示灯变为红灯,时好时坏.解决方案,长按指示键,待指示灯连续 ...

  6. MySQL 笔记整理(14) --count(*)这么慢,我该怎么办?

    笔记记录自林晓斌(丁奇)老师的<MySQL实战45讲> (本篇内图片均来自丁奇老师的讲解,如有侵权,请联系我删除) 14) --count(*)这么慢,我该怎么办? 有时你会发现,随着系统 ...

  7. WPF 自定义 ImageButton

    控件源码: public class ImageButton : Button    {        public ImageButton() {        } public string No ...

  8. [TCP/IP] 传输层-ethereal 抓包分析TCP包

    开启抓包工具抓取一个HTTP的GET请求,我的ip是10.222.128.159    目标服务器ip是140.143.25.27 握手阶段: 客户端 ===> SYN MSS=1460(我能接 ...

  9. Unable to execute 'doFinal' with cipher instance [javax.crypto.Cipher@4e025e0a]

    org.apache.shiro.crypto.CryptoException: Unable to execute 'doFinal' with cipher instance [javax.cry ...

  10. html文档知识补充

    13.form表单(*******) 功能:前后数据交互,帮你提交任意的数据 input通过控制type属性来展示不同的获取用户输入的页面效果 type属性总结: text:纯文本 password: ...