codeforces 496B. Secret Combination 解题报告
题目链接: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 解题报告的更多相关文章
- CodeForces 496B Secret Combination
Secret Combination Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- cf 496B Secret Combination
题目链接:B. Secret Combination You got a box with a combination lock. The lock has a display showing n d ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
随机推荐
- python基础教程1
python作为一种编程语言,诞生于1990年左右,算是一门比较年轻的语言(也算是90后吧),它是面向对象的,但不同于JAVA\C#那么严格要求一切皆对象,更接近于C++,是面向过程和面向对象的结合: ...
- Ruby基本语法规则
1.Ruby常用数据类型 Numbers, Strings, Booleans my_num = 25 my_boollean = true (or false) my_string = " ...
- Mac Pro 安装 cmake,报错 Warning: cmake-3.5.2 already installed, it's just not linked
1.先安装 brew,参考文章:Mac Pro 安装 Homebrew 软件包管理工具 2.执行安装命令 brew install cmake 出现警告提示: Warning: cmake-3.5.2 ...
- gcc 4.8.3 install centos
http://blog.csdn.net/xlx921027/article/details/17382643
- data_quick 进度
20131118 加入xml对L8卫星波段控制: 纠正波段顺序 QVProc20131125.7z: 完成L8的增强 以后的程序会添加ZY3号解析模块 QVProc20131126.7z: 新增 粗 ...
- .net实现微信公众账号接口开发
说起微信公众帐号,大家都不会陌生,使用这个平台能给网站或系统增加一个新亮点,直接进入正题吧,在使用之前一定要仔细阅读官方API文档. API文档地址:http://mp.weixin.qq.com/w ...
- codemirror和ace editor的语法高亮
两个javascript库用做在线代码编辑器都是非常优秀的选择 我这两天对这两个类库做了简单的研究,重点是语法高亮的自定义: ace editor的主要思路是生成状态机,从一个startstate开始 ...
- BZOJ 3111: [Zjoi2013]蚂蚁寻路
Sol DP. 首先观察转折,画画图,看看移动路线,可以非常轻易的发现如果走到起点的下方是回不去的.. 然后它就相当于一个底部是平的,顶部凹凹凸凸的形状,每右转两次或左转两次就会形成小矩阵,这样就可以 ...
- 7.在AngularJS视图中实现指令
指令扩展了HTML的行为.可以创建自定义的HTML元素,属性和特定于应用程序的类与功能. 1.了解指令 指令是AngularJS模板标记和用于支持的JavaScript代码的组合.AngularJS指 ...
- dp水题 序列问题 (9道)
9道题.A了8道,A题看题解也没弄懂怎么维护m段子序列的,过一段时间再回来看看 dp试水 47:56:23 125:00:00 Overview Problem Status Rank ( ...