大意: 给定两个字符串$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 (暴力)的更多相关文章

  1. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  2. 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 ...

  3. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  4. 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 ...

  5. 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 ...

  6. codeforces 691F 暴力

    传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...

  7. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...

  8. (CodeForces 548B 暴力) Mike and Fun

    http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...

  9. Link/Cut Tree CodeForces - 614A 暴力+爆 long long 处理

    题意: 给你一个区间[l,r],让你从小到大输出k^x,设y=k^x,要保证y在区间[l,r]中 题解: 就算k是最小的2也不需要枚举多少次就到long long的极限了,所以暴力没商量,根本不会TL ...

随机推荐

  1. DELPHI10.3.2安卓SDK安装

    DELPHI10.3.2安卓SDK安装 DELPHI10.3.2默认安装以后,还需要安装安卓SDK,才可以编译安卓项目. 1)运行Android Tools 2)勾选安装下面几个

  2. idea备忘

    1.idea 最近打开的文件个数 File->Settings->Editor->General->Editor Tabs->Tab Closing Policy-> ...

  3. yarn 单点故障 重启 ResourceManger Restart

    http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/ResourceManagerRestart.html Featur ...

  4. linux内核是如何支持深度睡眠(deep sleep)方式的?

    1. 硬件架构 arm64 2. 内核版本 4.19 3. 分析相关函数 setup_arch() -> psci_dt_init() -> psci_0_2_init() -> g ...

  5. 原生app是什么意思?

    原生的就是用 Android 和ios 写的 完全符合手机系统 其他的都是通过各种工具对代码转换为手机系统可以识别

  6. HTML5Audio/Video全解(疑难杂症)

    1.mp4格式视频无法在chrome中播放 Chrome浏览器支持HTML5,它支持原生播放部分的MP4格式(不用通过Flash等插件).为 什么是部分MP4呢?MP4有非常复杂的含义(见http:/ ...

  7. bing map for wpf 怎么显示中文地图

    添加一下代码: string suriFormat = "http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41"; Mic ...

  8. jQuery学习二

    1.id选择器: // 4.如果页面中多个元素id相同,jquery只会获取第一个id的jquery对象 var jquery = $('#name'); alert(jquery.val()); v ...

  9. Python3之定制类

    看到类似的__slots__这种形如__xxx__的变量或者函数名就要注意,这些在Python中是有特殊用途的 Python中还有许多有特殊用途的函数,可以帮助我们定制类 __str__ 先定义一个S ...

  10. Ubuntu LVS DR模式生产环境部署

    1.环境说明 系统版本:ubuntu14.04 LVS服务器:14.17.64.3 真实服务器:14.17.64.4-12 VIP:14.17.64.13 部署目的:用户请求14.17.64.13的报 ...