[原创]codeforces 664B Rebus [细节]
2016-09-01 15:54:48 Tabris_ 阅读数:491
博客爬取于2020-06-14 22:43:32
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/52400477
题目链接:http://codeforces.com/problemset/problem/664/B
---------------------------------.
B. Rebus
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
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.
Output
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.
Examples
input
? + ? - ? + ? + ? = 42
output
Possible
9 + 13 - 39 + 28 + 31 = 42
input
? - ? = 1
output
Impossible
input
? = 1000000
output
Possible
1000000 = 1000000
------------------------------------------.
题目大意 :
就是把问好(?)的数用1~n填上 如果存在等式能够成立的情况就输出Possible 和这个等式 (有SPJ)
否则输出Impossible
题目分析:
先把加上的数有几个 减去的数有几个统计一下
然后把每个数都附上1
接着把差的数匀乎匀乎就行了
附本题代码
----------------------------------.
# include<bits/stdc++.h> |


