题目链接: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. WP7/WP8/WP8.1设置存储的区别

    最近做的一个软件,由于最初是针对WP7的,现在在只能创建WP8.1的visual studio 2013上转换为了WP8的. 由于要保存字体大小.背景颜色.JSON三个数据,一直使用的是WP7下的存储 ...

  2. saltstack 入门命令

    master服务启动 CentOS 7 (Debian.OpenSuse.Fedora) systemctl start salt-master /etc/init.d/salt-master sta ...

  3. CSS3实现背景颜色渐变 摘抄

    一. Webkit浏览器 (1) 第一种写法: background:-webkit-gradient(linear ,10% 10%,100% 100%, color-stop(0.14,rgb(2 ...

  4. 内网安全工具之hscan扫描

    工具下载地址:hscan1.2.zip 界面简单,看配置: 这里我们主要需要配置的是模块和参数 模块,按照默认配置就行,取消 check HTTP vulnerability(漏洞检测) 会更快一点. ...

  5. u-boot 2011.09 开启debug 调试

    以前做过,现在刚才又想不起来了,这个错误非常的严重. 在这里记一下. debug 调试信息的开启在 include/common.h 有如下宏定义: #ifdef DEBUG #define debu ...

  6. BZOJ 2412: 电路检修

    Description [0,x]中全是1,其余全是0,每个点有一个权值,求最坏情况下得到x的最小权值. Sol DP+单调队列. 你可以去看我的这篇Blog...开这篇纯属为了骗访问... http ...

  7. IOS路线图

    存档,存档...

  8. 1.2---翻转字符串(CC150)

    import java.util.*; public class Reverse { public String reverseString(String iniString) { // write ...

  9. NDK学习4: Eclipse HelloWorld

    NDK学习4: Eclipse HelloWorld 1.配置Eclipse NDK环境  Window->preferences->android->ndk   2.新建Andro ...

  10. ASC47B borderless

    题目描述 border集合为{NULL,str}的串str称为borderless串. border即KMP里的那个. 字符集{'a','b'},给定长度n,求第k(给定)小的borderless串. ...