Replace A

Time limit: 1000 ms
Memory limit: 256 MB

 

You are given a string SS containing only letters A or B. You can take any two adjacent As and replace them by a single A. You perform operations as long as possible. Print the final string.

Standard input

The first line contains the string SS.

Standard output

Print the final string on the first line.

Constraints and notes

  • SS contains between 11 and 100100 characters.
Input Output Explanation
AAABB
ABB

At the first step you can choose the first two As, obtaining AABB.

At the second step, you can choose the only two adjacent As remaining, obtaining ABB.

You cannot do any more operations on this string.

和上次CF的A一样,直接暴力

#include<bits/stdc++.h>
using namespace std;
const int N=;
int main()
{
ios::sync_with_stdio(false);
string s,t;
cin>>s;
set<char>S;
S.insert('A');
while(true)
{
int f=;
for(int i=;s[i]&&f;i++)
{
if(S.count(s[i-])&&S.count(s[i]))
{
f=;
t=s.substr(,i)+s.substr(i+);
}
}
if(f)break;
s=t;
}
cout<<s;
return ;
}

Matrix Balls

Time limit: 1000 ms
Memory limit: 256 MB

 

You are given a matrix AA of size N \times MN×M, containing distinct elements. Initially there is a ball placed in every cell of the matrix. Each ball follows the following movement:

  • If the current cell is smaller than all of its (at most 88) neighbours, the ball stops in this cell;
  • otherwise, the ball moves to the smallest neighbouring cell.

Find for each cell of AA how many balls will end up there, when all the balls stop moving.

Standard input

The first line contains two integers NN and MM.

Each of the next NN lines contains MM integers representing the elements of AA.

Standard output

Print NN lines, each containing MM integers. The j^{th}j​th​​ element on the i^{th}i​th​​ line should represent the number of balls that end up in cell (i, j)(i,j).

Constraints and notes

  • 1 \leq N, M \leq 5001≤N,M≤500
  • 0 \leq A_{i, j} \leq 3*10^50≤A​i,j​​≤3∗10​5​​
Input Output Explanation
3 3
1 3 4
5 6 7
8 9 2
6 0 0
0 0 0
0 0 3

Considering a ball in each cell, matrix[i][j]matrix[i][j] represents the value to which that ball will move

00 represents a ball that does not move to any other location (the cell is the smallest of the 88 neighbours)

1
2
3
4
 
 
0 1 3
1 1 2
5 2 0
 
 
 
 

The value on which the ball will be placed after it moved as described in the statement

1
2
3
4
 
 
1 1 1
1 1 2
1 2 2
 
 
 
 
1 6
10 20 3 4 5 6
1 0 5 0 0 0
 
4 4
20 2 13 1
4 11 10 35
3 12 9 7
30 40 50 5
0 4 0 4
0 0 0 0
4 0 0 0
0 0 0 4

The value on which the ball will be placed after it moved as described in the statement

1
2
3
4
5
 
 
2 2 1 1
2 2 1 1
3 3 5 5
3 3 5 5
 
 
 
 

一个球可以向八个方向滚,滚到最小的里面,问最后每个那里面放几个

必须要记忆化搜索,但是要多搜几个方向的

#include<bits/stdc++.h>
using namespace std;
const int N=;
int a[N][N],b[N][N],n,m;
int d[][]= {,,,,,-,,,,-,-,,-,,-,-};
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=; i<n; i++)
for(int j=; j<m; j++)
cin>>a[i][j],b[i][j]=;
int f=;
while(f)
{
f=;
for(int i=; i<n; i++)
for(int j=; j<m; j++)
if(b[i][j])
{
int x=i,y=j;
for(int k=; k<; k++)
{
int tx=i+d[k][],ty=j+d[k][];
if(!(tx<||tx>=n||ty<||ty>=m)&&a[tx][ty]<a[x][y])
x=tx,y=ty;
}
if(x!=i||y!=j)
b[x][y]+=b[i][j],b[i][j]=,f=;
}
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
cout<<b[i][j]<<" ";
cout<<"\n";
}
return ;
}

按照数不同往下搜索

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+;
int d[][]= {,,,,,-,,,,-,-,,-,,-,-};
int n,m,a[][],b[][];
pair<int,int>g[N];
int main()
{
cin>>n>>m;
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
b[i][j]=,cin>>a[i][j],g[a[i][j]]=make_pair(i,j);
for(int i=; i>=; --i)
{
if(g[i].first==)continue;
int x=g[i].first,y=g[i].second,mi=i,sx=,sy=;
for(int j=; j<; j++)
{
int tx=x+d[j][],ty=y+d[j][];
if(tx<||ty<||tx>n||ty>m)continue;
if(a[tx][ty]<mi)
mi=a[tx][ty],sx=tx,sy=ty;
}
if(mi!=i)b[sx][sy]+=b[x][y],b[x][y]=;
}
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
cout<<b[i][j]<<" ";
cout<<"\n";
}
return ;
}

Binary Differences

Time limit: 1000 ms
Memory limit: 256 MB

 

You are given a binary array AA of size NN. We define the cost of a subarray to be the number of 00s minus the number of 11s in the subarray. Find the number of distinct values KK such that there is at least one subarray of cost KK.

Standard input

The first line contains one integer NN.

The second line contains NN integers (00 or 11) representing the elements of AA.

Standard output

Print the answer on the first line.

Constraints and notes

  • 1 \leq N \leq 10^51≤N≤10​5​​
  • The subarray may be empty
Input Output Explanation
3
0 1 0
3

We have 33 different costs:

  • [1, 0][1,0] has cost 00
  • [1][1] has cost -1−1
  • [0, 1, 0][0,1,0] has cost 11
4
1 0 0 1
4
  • [1, 0][1,0] has cost 00
  • [1, 0, 0][1,0,0] has cost 11
  • [0, 0][0,0] has cost 22
  • [1][1] has cost -1−1

这个是模拟

#include<bits/stdc++.h>
using namespace std;
int n,mi,ma,x,s,mis,mas;
int main()
{
cin>>n;
for(int i=; i<=n; ++i)
{
cin>>x;
if(!x)s++;
else s--;
mi=min(mi,s-mas),ma=max(ma,s-mis),mas=max(mas,s),mis=min(mis,s);
}
cout<<ma-mi+;
return ;
}

rsa Round #71 (Div. 2 only)的更多相关文章

  1. BestCoder Round #71 (div.2)

    数学 1001 KK's Steel 类似斐波那契求和 #include <cstdio> #include <cstring> #include <algorithm& ...

  2. BestCoder Round #71 (div.2) (hdu 5621)

    KK's Point Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)

    KK's Steel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. [Codeforces Educational Round 71]Div. 2

    总结 手速场...像我这种没手速的就直接炸了... 辣鸡 E 题交互,少打了个 ? 调了半个小时... 到最后没时间 G 题题都没看就结束了...结果早上起来被告知是阿狸的打字机...看了看题一毛一样 ...

  5. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  6. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  7. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

  8. Codeforces Beta Round #65 (Div. 2)

    Codeforces Beta Round #65 (Div. 2) http://codeforces.com/contest/71 A #include<bits/stdc++.h> ...

  9. (BestCoder Round #64 (div.2))Array

    BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...

随机推荐

  1. web端 复合控件 响应回发

    AutoPostback="true";   自动提交 RdiobuttonList 属性→设计→编辑项→{ Enabled   是否可用 selected 是否选中 Text   ...

  2. 【Python图像特征的音乐序列生成】使用Python生成简单的MIDI文件

    这个全新的Python音乐创作系列,将会不定期更新.写作这个系列的初衷,是为了做一个项目<基于图像特征的音乐序列生成模型>,实时地提取照片特征,进行神经网络处理,生成一段音乐. 千里之行, ...

  3. Installing Apache, PHP, and MySQL on Mac OS X

    I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each ...

  4. python基础教程总结15——2 画幅好画

    要求:从Internet上下载数据文件:  分析数据文件并提取感兴趣的部分 工具:图形生成包(ReportLab,PYX等) 数据:太阳黑子和射电辐射流量(http://services.swpc.n ...

  5. java.lang.ClassCastException: com.ch.hibernate.Student_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy

    利用query动态查询时,报错 java.lang.ClassCastException: com.ch.hibernate.Student_$$_javassist_0 cannot be cast ...

  6. stixel world论文总结

    1.The Stixel World - A Compact Medium Level Representation of the 3D-World:http://pdfs.semanticschol ...

  7. nfs-ganesha使用

    一 nfs-ganesha在centos7上安装 yum -y install centos-release-gluster yum install -y nfs-ganesha.x86_64yum ...

  8. 已知一棵完全二叉树,求其节点的个数 要求:时间复杂度低于O(N),N为这棵树的节点个数

    package my_basic.class_4; public class Code_08_CBTNode { // 完全二叉树的节点个数 复杂度低于O(N) public static class ...

  9. [BZOJ4327]:[JZOI2012]玄武密码(AC自动机)

    题目传送门 题目描述: 在美丽的玄武湖畔,鸡鸣寺边,鸡笼山前,有一块富饶而秀美的土地,人们唤作进香河.相传一日,一缕紫气从天而至,只一瞬间便消失在了进香河中.老人们说,这是玄武神灵将天书藏匿在此.  ...

  10. iOS开发遇到的坑之六--使用cocopods管理第三方库时,编译出现Library not found for -lPods问题的解决办法

    在项目中有时候会遇到Library not found for -lPods(这里的IPods指的是你具体的第三方库)的问题 出现这个错误的原因是:xcode在编译的时候找不到这个库,从而导致项目无法 ...