zoukankan      html  css  js  c++  java
  • Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题

    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=0;i<n;i++)
        {
            d[i]=s[i]-'0';
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                //cout<<"1"<<endl;
                hou[i][j]=d[(i+j)%n]-d[i];
                if(hou[i][j]<0)
                    hou[i][j]+=10;
            }
        }
        int flag1[maxn];
        memset(flag1,0,sizeof(flag1));
        int num=n;
        int m=0;
        int flag=0;
        //cout<<"1"<<endl;
        while(m!=n-1)
        {
            int min_num=11;
            for(int i=0;i<n;i++)
            {
                if(flag1[i]==0&&hou[i][m]<min_num)
                {
                    flag=i;
                    min_num=hou[i][m];
                }
            }
            for(int i=0;i<n;i++)
            {
                if(hou[i][m]>min_num)
                {
                    flag1[i]=1;
                    num--;
                }
            }
            m++;
            if(num==1)
                break;
        }
        //cout<<flag<<endl;
        int dp=s[flag]-'0';
        dp=10-dp;
        int kiss;
        //cout<<dp<<endl;
        for(int i=0;i<n;i++)
        {
            kiss=s[(i+flag)%n]-'0';
            if(s[(i+flag)%n]==s[flag])
                cout<<(kiss+dp)%10;
            else
                cout<<(kiss+dp)%10;
        }
        cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Array中使用异步函数遍历元素,Array循环同步执行
    vscode设置快捷键"h"快速生成html模板
    IOS(苹果手机)使用video播放HLS流,实现在内部播放及全屏播放(即非全屏和全屏播放)。
    FTP服务器与客户端的安装与配置
    移动端页面顶部滑动实现菜单的弹出与隐藏
    JS十大经典排序排序算法
    【bug】table重新加载数据,页面滚动条下沉到底部,记录scrollTop后将其恢复scrollTop出现闪烁
    寄生组合式继承
    扁平对象,转为树形对象
    使用CSS禁止textarea调整大小功能的方法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4172196.html
Copyright © 2011-2022 走看看