【codeforces 514A】Chewbaсca and Number
【题目链接】:http://codeforces.com/contest/514/problem/A
【题意】
允许你把每个数字翻转
->x变成9-x
然后问你能够变成的最小的数字是什么;
不能出现前导0,且最后必须是正数;
【题解】
第一个数字是9的话不能变;
其他数字;
大于等于5就翻转
这样就不会出现前导0了,也就不会出现为0的情况了;
(这题不允许翻转之后第一位数字为0,然后把前导0去掉)
【Number Of WA】
3
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
string s;
int a[N],b[N],j = 1;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> s;
int len = s.size();
rep1(i,1,len)
a[i] = s[i-1]-'0',b[i] = a[i];
if (a[1]==9) j = 2;
rep1(i,j,len)
if (a[i]>=5)
a[i]=9-a[i];
rep1(i,1,len)
printf("%d",a[i]);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 514A】Chewbaсca and Number的更多相关文章
- 【codeforces 546D】Soldier and Number Game
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)
Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...
- 【11.61%】【codeforces 670F】Restore a Number
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 805D】Minimum number of steps
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...
- 【codeforces 768C】Jon Snow and his Favourite Number
[题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
- 【codeforces 515B】Drazil and His Happy Friends
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...
随机推荐
- [BZOJ 3132] 上帝造题的七分钟
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3132 [算法] 二维树状数组 [代码] #include<bits/stdc+ ...
- thinkphp vender
vender在thinkphp里面时引入系统的类库的意思,具体用法如下. Vendor('Classes.PHPExcel');表示引入vendor目录下的classes文件夹下面的phpexcel文 ...
- codevs1312连续自然数和
1312 连续自然数和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 对于一个自然数M,求出所有的连续的自然数段 ...
- [Swift通天遁地]七、数据与安全-(12)使用Instruments Leaks工具检测内存泄露
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- ACM算法目录
数据结构 栈,队列,链表 •哈希表,哈希数组 •堆,优先队列 双端队列 可并堆 左偏堆 •二叉查找树 Treap 伸展树 •并查集 集合计数问题 二分图的识别 •平衡二叉树 •二叉排序树 •线段树 一 ...
- Java继承体系中this的表示关系
在继承关系下,父类中的this关键字并不总是表示父类中的变量和方法.this关键字的四种用法如前文所述,列举如下. 1) this(paras…); 访问其他的构造方法 2) this.xxx; 访问 ...
- T-SQL查询基础
今天来带大家了解下在sql server 中的查询机制 使用select语句进行查询 1.查询所有的数据行和列 select * from student 2.查询部分行和列 select scode ...
- HTML和CSS网页开发基础
一 HTML文档结构 HTML文档结构:<html>.<head>.<title>.<body>构成HTML页面中最基本的元素. HTML常用标记:1. ...
- Eclipse中搭建Apache Tomcat7源码调试环境
第一步:获取Apache Tomcat7源码,读者可以从Apache 官方网站获取,官方下载地址: http://tomcat.apache.org/download-70.cgi 注意选择Sourc ...
- 移动web——bootstrap模板
基本概念 1.bootstrap就是在媒体查询技术出现以后才开始出现的 2.此技术使响应式开发变得十分轻松,最大特点就是栅格系统(什么设备上如何显示)以及响应式工具(是否可见) 基本模板 <!D ...