Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B
1 second
256 megabytes
standard input
standard output
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer n is positive and doesn't exceed 1 000 000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.
The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise.
If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to n. Follow the format given in the samples.
? + ? - ? + ? + ? = 42
Possible
9 + 13 - 39 + 28 + 31 = 42
? - ? = 1
Impossible
? = 1000000
Possible
1000000 = 1000000
解题报告:
看到大神们的代码,简直碉堡了。
1、这里的输入要掌控好。
2、思路:先置每个位置为1,记录下加上的数的个数sa,减去的个数sb,这样,p(离目标结果)只差p-n了。
3、根据每个问号前面的符号,自增,达到结果。
#include <cstdio> using namespace std; int a[]; ///结果
int v[]; ///记录每个符号 char c[]; ///符号命令 int main()
{
scanf("%s",c); ///输入问号
scanf("%s",c); ///输入符号
int m=; ///?的个数,即要填的数字的个数
int sa=; ///加数的个数
int sb=; ///减数的个数
v[]=; while(c[]!='=')
{
if(c[]=='+')
{
v[++m]=;
sa++;
}
else {
v[++m]=-;
sb++;
}
scanf("%s",c);///输入问号
scanf("%s",c);///输入符号
} int n;
scanf("%d",&n); ///目标结果 for(int i=;i<=m;i++) ///全部填上1
a[i]=; int p=sa-sb; for(int i=;i<=m;i++) ///一个一个处理各个数
{
while((p<n)&&(v[i]==)&&(a[i]<n))
a[i]++,p++;
while((p>n)&&(v[i]==-)&&(a[i]<n))
a[i]++,p--;
} if(p!=n)
{
printf("Impossible\n");
return ;
}
printf("Possible\n");
printf("%d ",a[]); for(int i=;i<=m;i++)
{
if(v[i]==) printf("+ ");
else printf("- ");
printf("%d ",a[i]);
}
printf("= %d\n",n);
}
Codeforces Round #347 (Div.2)_B. Rebus的更多相关文章
- Codeforces Round #347 (Div. 2) B. Rebus
题目链接: http://codeforces.com/contest/664/problem/B 题意: 给你一个等式,把等式左边的问号用1到n(n为等式右边的数)的数填好,使得等式成立 题解: 贪 ...
- Codeforces Round #347 (Div. 2)
unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- Codeforces Round #347 (Div.2)_A. Complicated GCD
题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...
- Codeforces Round #290 (Div. 2) _B找矩形环的三种写法
http://codeforces.com/contest/510/status/B 题目大意 给一个n*m 找有没有相同字母连起来的矩形串 第一种并查集 瞎搞一下 第一次的时候把val开成字符串了 ...
- Codeforces Round #347 (Div. 2) (练习)
A: 题意:找到[a, b]的最大公约数: 思路:相同时为本身,不同时为1. 套路:碰到水题别想太多: 猜想:两个相邻数,必有一奇一偶,如果偶数有因子3或者其他,奇数可不可能有相同的呢? 枚举一些数后 ...
- codeforces Round #347 (Div. 2) C - International Olympiad
思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...
- Codeforces Round #366 (Div. 2)_B. Spider Man
B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #332 (Div. 2)_B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- WEB视频播放器插件,总结
WEB视频播放器插件,总结 2018年07月29日 20:42:11 流光忆莲 阅读数:572更多 个人分类: 推荐文章收藏 以下是关于网页中嵌入视频播放插件的各种资料的总结 基于H5的Vedio ...
- 约瑟夫环问题poj1012
题意: 有k个坏人k个好人坐成一圈,前k个为好人(编号1~k),后k个为坏人(编号k+1~2k) 现在有一个报数m,从编号为1的人开始报数,报到m的人就要自动死去. 问当m为什么值时,可以使得在出现好 ...
- maya2014无法安装卸载激活失败
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- LeanTouch控制移动
Lean_Touch控制移动 using UnityEngine; using System.Collections; using System.Collections.Generic; using ...
- Murano Weekly Meeting 2016.07.12
Meeting time: 2016.July.12 1:00~2:00 Chairperson: Kirill Zaitsev, from Mirantis Meeting summary: 1. ...
- (转)Python3.5 day3作业二:修改haproxy配置文件
原文:http://www.cnblogs.com/iwxk/p/6010018.html
- git 基础教程
git 提交 全部文件 git add . git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件.注意 -A 选项后面还有一个 ...
- 通过进入单用户模式解决linux中的rc.local修改后无法启动的问题
问题:本想将teamviewer这个软件随linux自启动,所以将其启动命令放在rc.local中,但是重启后发现linux启动不起来了,系统前面都是正常启动的,就是无法进入帐户登陆界面,无法输入ro ...
- InnoDB还是MyISAM?
两种类型最主要的差别就是Innodb 支持事务处理与外键和行级锁.而MyISAM不支持.所以MyISAM往往就容易被人认为只适合在小项目中使用. 我作为使用MySQL的用户角度出发,Innodb和My ...
- JEECMS站群管理系统-- Jeecms项目导入myeclipse
1.在myeclipse中新建一个项目jeecms,将服务器中jeecms项目下web-inf文件夹下内容拷到新建项目中 解压缩jeecms-3.0.2-final-src,在src文件夹下会看到有三 ...