Codeforces Round #283 (Div. 2) A B C

来源:互联网 发布:360下载不了软件 编辑:程序博客网 时间:2024/06/06 09:55

A - Minimum Difficulty

给出n个数字,删去一个数之后的求剩下的n-1个数之间的差最大值最小的那个值。

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int N = 105;int a[N], c[N], z[N];int main(){    int n;    while(~scanf("%d", &n))    {        for( int i = 1; i <= n; i ++)        {            scanf("%d", &a[i]);        }        for( int i = 2; i <= n; i ++)            c[i] = a[i] - a[i-1];        for( int i = 3; i <= n; i ++ )            z[i] = a[i] - a[i-2];        int ans = 99999999;        for( int i = 2; i < n; i++ )        {            int q = 0, w = z[i+1];            for( int j = 2; j <= n; j++ )            {                if( i == j || j == i + 1 )                    continue;                q = max(q, c[j]);            }            ans = min(ans, max(q, w));        }        printf("%d\n", ans);    }    return 0;}
B - Secret Combination

按照题目的操作,1 移位:最右移到最左,其他向右移一位 2每个数位上+1.问经过多次操作之后能得到的最小的数,要求输出前导零

摘自党 http://www.cnblogs.com/radical/p/4171487.html

#include <iostream>#include <string>using namespace std;string ans , str;void solve( ){    string s , t;    char ch;    int len = str.length();    int temp;    for( int T = 1 ; T<=10 ; T++ )    {        s = "";        for( int i = 0 ; i<len ; i++ )        {            temp = (str[i]-'0'+T)%10;//char转int            ch = temp + '0';//int转char            s += ch;        }        if( s<ans )            ans = s;        for( int j = 1 ; j<len ; j++ )        {            t = "";            t.append(s,j,len-j);            t.append(s,0,j);            if( t<ans )                ans = t;        }    }}int main(){    int n;    cin >> n;    cin >> str;    ans = str;    solve( );      cout << ans << endl;}
C - Removing Columns 

n*m的字符矩阵,每次比较相邻两行的字符串,要求下面的字符串字典序大于等于上面的,不行则删除某列继续比较。时间大概是在n*m*n*m

//http://codeforces.com/contest/496/problem/C#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int N = 105;int vis[N];char a[N][N];int main(){int n, m;while(~scanf("%d%d", &n, &m)){memset(vis, 0, sizeof(vis));for( int i = 1; i <= n; i ++ )scanf("%s", a[i]+1);if( n == 1 ){puts("0");continue;}int ans = 0;int i;while(1){bool ok = 0;for( i = 2; i <= n; i++ ){for( int j = 1; j <= m; j++ ){if( vis[j] )continue;if( a[i][j] < a[i-1][j] ){vis[j] = 1;ans++;ok = 1;break;}else if( a[i][j] == a[i-1][j] )continue;elsebreak;}if( ok )break;}if( i > n )break;}printf("%d\n", ans);}return 0;}/*3 5abcxyacaxyaaaxy*/


0 0
原创粉丝点击