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. win7 64位mysql安装及navicat 解压版

    教程:http://jingyan.baidu.com/article/f3ad7d0ffc061a09c3345bf0.html Mysql修改设置root密码的命令及方法:http://jingy ...

  2. Django中cookie和session

    cookie Cookie的由来 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不 ...

  3. 一张图教会CSS3倒影

    分享 示例图片 在CSS3之前,想要实现示例图片这样的一个倒影效果一般只能通过处理图片的方式,而CSS3问世之后,想要实现这样的效果变得非常简单,只需一个CSS3属性就可以轻松实现了. 这就是今天所要 ...

  4. 【鬼脸原创】谷歌扩展--知乎V2.0

    目的: 用键盘替代鼠标,做一个安静刷知乎的美男(女)子! 功能:   功能 按键 说明 直接定位到搜索框 q   打开 首页 w   打开 话题 e   打开 发现 r   打开 消息 m   打开 ...

  5. ASP .Net Core系统部署到 CentOS7 64 具体方案

    .Net Core 部署到 CentOS7 64 位系统中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是 ...

  6. Apache Lucene版本迁移指南

    http://lucene.apache.org/core/4_0_0/MIGRATE.html 本文详细介绍了lucene的版本升级过程中的重大改进与调整. 比如:灵活的索引改变了低水平的域.词.文 ...

  7. wpf mvvm模式下的image绑定

    view文件 <Image Grid.Column="2" Width="48" Height="64" Stretch=" ...

  8. 关于SizeOf、Length

    结论: 到底什么时候用Length,SizeOf呢,我总结下使用Length,Sizeof的场景 1.Length(静态数组或动态数组)----没有问题 2.Length(string/shortst ...

  9. C++11之auto和decltype

    auto自动类型推断,用于从初始表达式中推断出变量的类型. auto a;// 错误,没有初始化表达式,无法推断出a的类型 autoint a =10;// 错误,auto临时变量的语义在C++ 11 ...

  10. Two Seals codeforces 837c

    Two Seals 一个矩形a*b,若干子矩形,子矩形中选2个,不重叠能覆盖最大 思路: 枚举: 代码: #include <cstdio> #include <cstring> ...