大意: 给定两个字符串$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. Linux 使用 you-get 指令下载网页视频

    今天无意中发现一个下载网页视频的好办法 在 Linux 系统中,可以利用 you-get 指令直接下载网页中的视频 1.更新 sudo apt-get update 2.安装 pip sudo apt ...

  2. Java 方法与数组

    方法 什么是方法? 方法定义:方法(Method),函数(function),其实就指一个特定的功能操作,程序中完成独立功能,可重复使用的一段代码的集合. 方法的定义 方法定义格式: [修饰符] 返回 ...

  3. 关于浏览器请求PHP一次请求执行了两次

    测试同学今天又双叒反馈了一个Bug 继上次解决了重复请求的问题之后,本来就以为可以万事大吉了,没想到我还是太年轻了,测试同学说,不行啊,老哥,你这个我点击了一次创建居然创建出来两条数据!!并且查看日志 ...

  4. oracle库两个表关联查询时用 count 报错【我】

    oracle数据库,需要对两个表进行关联查询(根据两个字段),结果发现关联后不能改为 count 获取数量,报错如下: 同样的sql换到另外一个数据库就可以(只是因为数据量在千万级,所以很慢,用时40 ...

  5. sha256C代码例子

    a.c #include <stdio.h>#include <string.h>#include <openssl/sha.h> 1 int main(int a ...

  6. LeetCode_104. Maximum Depth of Binary Tree

    104. Maximum Depth of Binary Tree Easy Given a binary tree, find its maximum depth. The maximum dept ...

  7. 【Leetcode_easy】686. Repeated String Match

    problem 686. Repeated String Match solution1: 使用string类的find函数: class Solution { public: int repeate ...

  8. react 生命周期函数的一些心得体会

    一.理论 组件本质上是状态机,输入确定,输出一定确定 生命周期的三个阶段,三者时间是不固定的,只是在逻辑上的分类: 二.初始化阶段: getDefaultProps:获取实例的默认属性(即使没有生成实 ...

  9. C入门笔记

    教程总体概括:Mac OS X系统简介:C语言:OC语言:Foundation:iOS开发:项目实战. 3.第一个c语言程序#include <stdio.h>//预处理指令:在编译之前执 ...

  10. charles 高级批量请求

    本文参考:charles 高级批量请求 这个我感觉有点鸡肋,真正的批量请求,推荐使用JMter charles 高级批量请求就是下面这种简单的设置的 简单的使用还是可以的; 比如简单的测试下,向某一个 ...