Once in a casino CodeForces - 1120B (暴力)
大意: 给定两个字符串$a,b$, 每个字符为$0-9$, 每次操作将$a$中相邻两位加$1$或减$1$, 操作后每个数仍要为$0-9$, 求最少操作使$a$变成$b$.
先不考虑范围, 判断是否成立. 然后暴力输出方案即可
#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
typedef long long ll; const int N = 1e6+10;
int n;
char s[N], t[N];
ll ans, a[N]; void dfs(int x, int w) {
if (s[x+1]+w<'0'||s[x+1]+w>'9') dfs(x+1,-w);
printf("%d %d\n",x,w);
s[x] += w;
s[x+1] += w;
if (!--ans) exit(0);
} int main() {
scanf("%d%s%s", &n, s+1, t+1);
REP(i,1,n) {
a[i] = -a[i-1]+t[i]-s[i];
ans += abs(a[i]);
}
if (a[n]) return puts("-1"),0;
printf("%lld\n", ans);
if (!ans) return 0;
ans = min(ans, (ll)1e5);
REP(i,1,n-1) {
while (s[i]!=t[i]) dfs(i,t[i]>s[i]?1:-1);
}
}
Once in a casino CodeForces - 1120B (暴力)的更多相关文章
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- codeforces 691F 暴力
传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...
- Vicious Keyboard CodeForces - 801A (暴力+模拟)
题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...
- (CodeForces 548B 暴力) Mike and Fun
http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...
- Link/Cut Tree CodeForces - 614A 暴力+爆 long long 处理
题意: 给你一个区间[l,r],让你从小到大输出k^x,设y=k^x,要保证y在区间[l,r]中 题解: 就算k是最小的2也不需要枚举多少次就到long long的极限了,所以暴力没商量,根本不会TL ...
随机推荐
- nrm切换npm包源
nrm可以随时切换npm包的源 npm install -g nrm 安装nrm完成 查看nrm源 nrm ls 切换源 npm use npm #也可以切换成其他源
- 雪花算法(DELPHI实现)
雪花算法(DELPHI实现) 生成ID能够按照时间有序生成. 分布式系统内不会产生重复id(用workerId来做区分). 自增ID:对于数据敏感场景不宜使用,且不适合于分布式场景. GUID:采用无 ...
- openstack instance change storage dir
在云计算openstack中以为新建的虚拟机都存放在/var/lib/nova/instances中,在新建虚拟机时内存当然不够用,所以可以将nova转移到新的存储位置 以下操作只在计算节点上进行 一 ...
- VUE判断可用对象是否为空
方法一: JSON.stringify(formmanage_listVue.updataObj)=='{}' var data = {}; var b = (JSON.stringify(data) ...
- 分享调试SI4432的一些小经验(转)
分享调试SI4432的一些小经验 最近使用 STM8F103 + SI4432 调无线,遇到问题不少,此处有参考过前辈的经验: 1.硬件把板给到我时USB烧录线带供电(5V),此供电接到LDO输出,就 ...
- 机器学习 - 算法 - SVM 支持向量机
SVM 原理引入 支持向量机( SVM,Support Vector Machine ) 背景 2012年前较为火热, 但是在12年后被神经网络逼宫, 由于应用场景以及应用算法的不同, SVM还是需要 ...
- python argparse例子实践
python 解析命令行读取参数,在多个文件或者不同语言协同的项目中,python脚本经常需要从命令行直接读取参数. 万能的python自带了sys.arg.argparse.optparse模块等, ...
- sql数据库为null时候ASP语句判断问题
我有一个表test1,有字段num,字段num有null值,也有空值,也有其他值,我要用asp语句判断我查询出来的num的值是否为null值.应该怎么写 严谨一点,要有两层判断: If IsNull( ...
- 26Flutter 日期 和时间戳/格式化日期库/flutter异步/ 官方自带日期组件showDatePicker、时间组件showTimePicker以及国际化
/* 一.Flutter日期和时间戳 日期转换成时间戳 var now=newDateTime.now(); print(now.millisecondsSinceEpoch); //单位毫秒,13位 ...
- Windows下安装ActiveMQ
到官网(http://activemq.apache.org/download-archives.html)下载最新发布的压缩包(我下的是5.15.9)到本地后解压(我解压到D盘Dev目录下)即可.进 ...