题目链接:http://codeforces.com/problemset/problem/496/B

题目意思:给出 n 位数你,有两种操作:1、将每一位数字加一(当某一位 > 9 时只保存个位数)   2、循环右移(最右边那个数字去到第一位上)。问经过若个两种操作的组合后,得到的最小数值为多少。

我一开始用了vector来做= =,没有考虑到循环右移的情况。以为每一位从1加到9之后,找出最小的那个就可以.....

  留个纪念(错误代码,别学,如果没有循环右移的限制,这个是对的)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std; const int maxn = 1e3 + ;
vector<int> v[maxn];
int a[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
char ch;
while (scanf("%d", &n) != EOF)
{
getchar();
v[].clear();
for (int i = ; i < n; i++)
{
scanf("%c", &ch);
a[i] = ch - '';
}
for (int i = ; i < ; i++)
{
for (int j = ; j < n; j++)
{
int add = a[j] + (i+);
v[i].push_back(add % );
}
sort(v[i].begin(), v[i].end());
}
sort(v, v+);
for (int i = ; i < n; i++)
printf("%d", v[][i], i == n- ? ' ' : '\n');
}
return ;
}

  按照步骤一步一步模拟即可。但是需要用到 b 数组来还原原始的数字。还有就是循环右移其实等价于循环左移!最后就是strcmp() 放到 get_reverse() 后面,这样需要两个strcmp 判断(循环外的add后面),这样放置只需要用到一次 strcmp() 就行了。放置位置也是值得注意的,不要颠倒了。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e3 + ;
char a[maxn];
int n; void add(char a[], int added)
{
for (int i = ; i < n; i++)
{
int tmp = (a[i]-'' + added) % ;
a[i] = tmp + '';
}
} void get_reverse(char a[])
{
char tmp = a[];
for (int i = ; i < n; i++)
a[i-] = a[i];
a[n-] = tmp;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%d", &n) != EOF)
{
getchar();
char b[maxn] = {''};
char ans[maxn] = {''};
for (int i = ; i < n; i++)
scanf("%c", &a[i]);
for (int i = ; i <= ; i++)
{
strcpy(b, a);
add(a, i);
for (int j = ; j < n; j++)
{
if (strcmp(ans, a) > )
strcpy(ans, a);
get_reverse(a);
}
strcpy(a, b);
}
puts(ans);
}
return ;
}

codeforces 496B. Secret Combination 解题报告的更多相关文章

  1. CodeForces 496B Secret Combination

    Secret Combination Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  2. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  3. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  4. cf 496B Secret Combination

    题目链接:B. Secret Combination You got a box with a combination lock. The lock has a display showing n d ...

  5. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  6. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

  7. codeforces 591A. Wizards' Duel 解题报告

    题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...

  8. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  9. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

随机推荐

  1. input lable水平对齐

    1.CSS <style type="text/css">       input,label { vertical-align:middle;} </style ...

  2. superF12

    superF12是开发内嵌ie内核的桌面客户端时的一个调试工具

  3. 微信事业群WXG成立 致力于打造微信大平台

    今天,微信之父张小龙带领微信团队成立微信事业群(WeiXin Group,简称WXG),致力于打造微信大平台,由他们负责微信基础平台.微信开放平台.微信支付拓展.O2O等微信延伸业务的发展,并包括邮箱 ...

  4. 第12天 android studio

    1. http://jingyan.baidu.com/article/215817f7888dc21eda14230d.html Gradle DSL method not found:‘andro ...

  5. linux 之常见的好用命令

    参考网址:软件匠艺小组之第八期把命令行玩飞起来 1.如果想要将文件重定向到文件里,而又想看重定向的内容, tee命令 例如:ls | tee foot.txt 2.如果想要字母显示为大写独特的,命令: ...

  6. Javascript高级程序设计——基本类型和引用类型的值

    ECMAScript中的变量有两种不同的数据类型的值: 基本类型:基本类型的值是简单的数据段.包括:Undefined.Null.Number.Boolean.String五种 引用类型:引用类型的值 ...

  7. STL next_permutation和prev_permutation函数

    利用next_permutation实现全排列升序输出,从尾到头找到第一个可以交换的位置, 直接求到第一个不按升序排列的序列. #include <iostream> #include & ...

  8. PHP开发神器——phpstorm

    常用快捷键 快捷键 说明 ctrl+j 插入活动代码提示 ctrl+alt+t 当前位置插入环绕代码 alt+insert 生成代码菜单 Shift + Enter 新一行 ctrl+q 查看代码注释 ...

  9. ShellCode框架(Win32ASM编写)

    主要方法: 使用宏的一切技巧让编译器 算出代码的长度 有较好的扩充性 include ShellCodeCalc.inc ;>>>>>>>>>&g ...

  10. How can I determine the URL that a local Git repository was originally cloned from?

    git remote show origin from: http://stackoverflow.com/questions/4089430/how-can-i-determine-the-url- ...