Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题
2 seconds
256 megabytes
standard input
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.
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.
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
3
579
024
4
2014
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 暴力水题的更多相关文章
- 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 ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- 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 ...
- 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 ...
- 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 ...
- 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, ...
- 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 ...
- 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 ...
随机推荐
- Linux内核跟踪之syscall tracer 【转】
转自:http://blog.chinaunix.net/uid-20543183-id-1930847.html ------------------------------------------ ...
- aarch64_g5
gtkmm24-devel-2.24.5-2.fc26.aarch64.rpm 2017-02-11 18:17 620K fedora Mirroring Project gtkmm24-docs- ...
- Django中HttpRequest和HttpResponse
请求和响应对象 Django中通过使用请求和响应对象来传递系统的状态. 当请求一个页面的时候,Django就创建一个HttpRequest对象,它包含了关于请求的元数据对象,然后Django加载适当的 ...
- Intel大坑之一:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
缘由 最近在写一些字符串函数的优化,兴趣使然,可是写的过程中,想要实现 128bit 的按 bit 逻辑位移,遇到了一个大坑,且听我娓娓道来. 如果要追究标题,更确切的是丢失的SSE2 128 bit ...
- spring学习之一概念
概念 1.是开源的轻量级框架 2.是一站式框架,就是说在java ee的三层结构中,每一层它都提供了不同的解决技术 web层:springMVC servoce层:spring IOC ,控制反转,通 ...
- scrapy shell命令的【选项】简介
在使用scrapy shell测试某网站时,其返回400 Bad Request,那么,更改User-Agent请求头信息再试. DEBUG: Crawled () <GET https://w ...
- IP地址、域名、域名解析系统相关
IP地址(Internet Protocol Address) 它来自TCP/IP协议,存在于其中的IP层,用于实现不同计算机之间的通信,类似于门牌号. 设计之处,IP地址是准备给地球上每一台计算机一 ...
- 回归模型效果评估系列2-MAE、MSE、RMSE、MAPE(MAPD)
MAE.MSE.RMSE.MAPE(MAPD)这些都是常见的回归预测评估指标,重温下它们的定义和区别以及优缺点吧 MAE(Mean Absolute Error) 平均绝对误差 ...
- SQL Server中删除表中重复数据
方法一:利用游标,但要注意主字段或标识列 declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max beg ...
- SQL 标量函数-----日期函数 day() 、month()、year()
select day(createtime) from life_unite_product --取时间字段的天值 select month(createtime) from life_unite_p ...