[Codeforces] Round #284 (Div. 2) A 、 B 、 C

来源:互联网 发布:儿童手表下载软件 编辑:程序博客网 时间:2024/05/19 08:22

496A. Minimum Difficulty

题意:给定n个数,每次可以拿掉除两端两个数外的任意一个数。设剩余相邻数字差的最大值为Max,求Max的最小值。

#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <set>#include <map>#include <queue>#include <stack>#include <assert.h>#include <time.h>//#define _Testtypedef long long LL;const int INF = 500000001;const double EPS = 1e-9;const double PI = acos(-1.0);using namespace std;int main(){    #ifdef _Test        freopen("test0.in", "r", stdin);        freopen("test0.out", "w", stdout);        srand(time(NULL));    #endif    int n, a[105], ans;    while(~scanf("%d", &n))    {        for(int i = 0; i < n; ++i)        {            scanf("%d", &a[i]);        }        ans = 1e9;        for(int i = 1; i < n-1; ++i)        {            int temp = -1;            for(int j = 1; j < n; j++)            {                if(j == i)                {                    continue;                }                else if(j != i+1)                {                    temp = max(a[j]-a[j-1], temp);                }                else                {                    temp = max(a[j]-a[j-2], temp);                }            }            ans = min(ans, temp);        }        printf("%d\n", ans);    }    return 0;}

496B. Secret Combination

题意:输入一个数字n,接着输入长度为n的字符串。现对这个字符串有两种操作:1.把这个字符串的最后一位挪到字符串的最前面 2.把这个字符串的每一位都加1。9+1=0.

求字典序最小的字符串。

比赛的时候,记录字符串的len变量写成char类型了,FST了。。

#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <set>#include <map>#include <queue>#include <stack>#include <assert.h>#include <time.h>//#define _Testtypedef long long LL;const int INF = 500000001;const double EPS = 1e-9;const double PI = acos(-1.0);using namespace std;int main(){    #ifdef _Test        freopen("test0.in", "r", stdin);        freopen("test0.out", "w", stdout);        srand(time(NULL));    #endif    char ch[1005], ch2[1005];    int n, len;    while(~scanf("%d", &n))    {        set<string> ss;        scanf("%s", ch);        len = strlen(ch);        for(int k = 0; k <= 9; k++)        {            for(int i = 0; i < len; ++i)            {                for(int j = 0; j < len; ++j)                {                    ch2[(j+i)%len] = (ch[j]-'0'+k)%10+'0';                }                ch2[len] = '\0';                ss.insert(ch2);            }        }          set<string>::iterator it = ss.begin();        printf("%s\n", (*it).c_str());    }    return 0;}

496C. Removing Columns

题意:给定n行m列的字符,每次可以删掉某一列的字符。求每行字符串从上至下是字典序至少需要删除几列字符。

根据字典序的规则,删除的规则一定是从左往右删,删的原则是前N列不是字典序的时候,把第N列删掉即可,直接按列递推字典序即可。

提供一组测试数据:

4 6
addddd
bccccc
bbaaca
caaaab

Answer:4

#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <set>#include <map>#include <queue>#include <stack>#include <assert.h>#include <time.h>#define _Testtypedef long long LL;const int INF = 500000001;const double EPS = 1e-9;const double PI = acos(-1.0);using namespace std;int main(){    #ifdef _Test        //freopen("test0.in", "r", stdin);        //freopen("test0.out", "w", stdout);        srand(time(NULL));    #endif    char ch[101][105];    int n, m;    int bl[105][105];    while(~scanf("%d %d", &n, &m))    {        for(int i = 0; i < n; i++)        {            scanf("%s", ch[i]);        }        int ans = 0;        for(int j = 0; j < m; j++)        {            int flag = 1;            bl[0][j] = 1;            for(int i = 1; i < n; i++)            {                if(ch[i][j] < ch[i-1][j] && (j == 0 || bl[i][j-1] <= 1))                {                    flag = 0;                    break;                }                else if(ch[i][j] == ch[i-1][j] && (j == 0 || bl[i][j-1] == 1))                {                    bl[i][j] = 1;                }                else if(j == 0 || bl[i][j-1] >= 1)                {                    bl[i][j] = 2;                }                 else                {                    bl[i][j] = 0;                }            }            if(!flag)            {                ++ans;                 for(int i = 0; i < n; i++)                {                    ch[i][j] = ch[0][j];                    if(j == 0)                        bl[i][j] = 1;                    else                        bl[i][j] = bl[i][j-1];                }            }        }       printf("%d\n", ans);    }    return 0;}



0 0
原创粉丝点击