B. Secret Combination
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

Output

Print a single line containing n digits — the desired state of the display containing the smallest possible number.

Sample test(s)
Input
3
579
Output
024
Input
4
2014
Output
0142

hou[i][j]表示当i为开头的时候,i后第j位的大小是多少
然后暴力枚举比较就行 n^2
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1001
const int inf=0x7fffffff; //无限大
string s;
int d[maxn];
int hou[maxn][maxn];
int main()
{
int n;
while(cin>>n){
cin>>s;
for(int i=;i<n;i++)
{
d[i]=s[i]-'';
}
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
//cout<<"1"<<endl;
hou[i][j]=d[(i+j)%n]-d[i];
if(hou[i][j]<)
hou[i][j]+=;
}
}
int flag1[maxn];
memset(flag1,,sizeof(flag1));
int num=n;
int m=;
int flag=;
//cout<<"1"<<endl;
while(m!=n-)
{
int min_num=;
for(int i=;i<n;i++)
{
if(flag1[i]==&&hou[i][m]<min_num)
{
flag=i;
min_num=hou[i][m];
}
}
for(int i=;i<n;i++)
{
if(hou[i][m]>min_num)
{
flag1[i]=;
num--;
}
}
m++;
if(num==)
break;
}
//cout<<flag<<endl;
int dp=s[flag]-'';
dp=-dp;
int kiss;
//cout<<dp<<endl;
for(int i=;i<n;i++)
{
kiss=s[(i+flag)%n]-'';
if(s[(i+flag)%n]==s[flag])
cout<<(kiss+dp)%;
else
cout<<(kiss+dp)%;
}
cout<<endl;
}
return ;
}

Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题的更多相关文章

  1. Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  3. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  4. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  5. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  6. Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集

    D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...

  8. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #603 (Div. 2) D. Secret Passwords(并查集)

    链接: https://codeforces.com/contest/1263/problem/D 题意: One unknown hacker wants to get the admin's pa ...

随机推荐

  1. aarch64_g1

    GAPDoc-1.5.1-12.fc26.noarch.rpm 2017-02-14 07:37 1.0M fedora Mirroring Project GAPDoc-latex-1.5.1-12 ...

  2. 12 Release History for go go语言的版本历史

    Release History Release Policy go1.11 (released 2018/08/24) go1.10 (released 2018/02/16) Minor revis ...

  3. C# byte[] 转换16进制字符串

    1.byte[] 转换16进制字符串 1.1 BitConverter方式 var str = DateTime.Now.ToString(); var encode = Encoding.UTF8; ...

  4. 字体格式类型(.eot/.otf/.woff/.svg)

    @font-face语句是css中的一个功能模块,用于实现网页字体多样性的模块(设计者可随意指定字体,不需要考虑浏览者电脑上是否安装). @font-face文件 而由于网页中使用的字体类型,也是各浏 ...

  5. 移动端,PC端,微信等常用平台和浏览器判断

    var wzw={ //浏览器相关信息 //android webview 需要app进行支持,Android web view初始化时,在navigator中添加标识 browser:{ versi ...

  6. Trie树子节点快速获取法

    今天做了一道leetcode上关于字典树的题:https://leetcode.com/problems/word-search-ii/#/description 一开始坚持不看别人的思路,完全自己写 ...

  7. C++静态成员的应用

    当在类外部定义静态成员时,不能重复使用static关键字 静态成员函数不包含this指针(无论是显示还是隐式使用) 静态成员可以通过类对象进行访问,也可以通过类进行访问 静态成员不是由构造函数初始化的 ...

  8. Linux学习笔记:vi常用命令

    在Linux系统中常用vi命令进行文本编辑. vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器.Linux中的vi编辑器叫vim,它是vi的增强版(vi Improved), ...

  9. GreenPlum学习笔记:基础知识

    一.介绍 GreenPlum分布式数据仓库,大规模并行计算技术. 无共享/MPP核心架构 Greenplum数据库软件将数据平均分布到系统的所有节点服务器上,所以节点存储每张表或表分区的部分行,所有数 ...

  10. 一步一步学习IdentityServer3 (9)

    idr添加验证码,授权方法中获取不到session,而且没有login页面的post方法,只有一个视图,而且是先加载视图,生成不了验证码 我的解决方法是将验证写一个自定义mvc控件  利用 viewd ...