题目链接:

B. Rebus

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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
Possible9 + 13 - 39 + 28 + 31 = 42

input
? - ? = 1

output
Impossible

input
? = 1000000

output
Possible1000000 = 1000000

题意:

给一个式子,让你选[1,n]中间的数把问号替换掉,使这个式子成立;

思路:

分分情况乱搞乱搞就行了,一次A不掉多搞几次就A了;

AC代码:
/*2014300227    664B - 14    GNU C++11    Accepted    15 ms    2036 KB*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+5;
typedef long long ll;
const int mod=1e9+7;
char str[110];
int ans[110],an[110];
int main()
{int cnt=0;int num1=0,num2=0,n;char s;while(1){scanf("%c",&s);if(s=='+'){num1++;str[cnt++]=s;}else if(s=='-'){num2++;str[cnt++]=s;}else if(s=='=')break;}num1++;scanf("%d",&n);int l=num1-num2*n;int r=num1*n-num2;if(n>=l&&n<=r){printf("Possible\n");if(num1-num2>n){for(int i=0;i<num1;i++){ans[i]=1;}int number=(num1-n)/num2;for(int i=0;i<num2;i++){if(i<(num1-n)%num2)an[i]=number+1;else an[i]=number;}}else if(num2-num1>n){for(int i=0;i<num2;i++){an[i]=1;}int number=(num2+n)/num1;for(int i=0;i<num1;i++){if(i<(num2+n)%num1)ans[i]=number+1;else ans[i]=number;}}else{int number=(n+num2)/num1;for(int i=0;i<num1;i++){if(i<(n+num2)%num1)ans[i]=number+1;else ans[i]=number;}for(int i=0;i<num2;i++){an[i]=1;}}printf("%d ",ans[0]);int cut=1,cu=0;for(int i=0;i<cnt;i++){printf("%c ",str[i]);if(str[i]=='+'){printf("%d ",ans[cut++]);}else printf("%d ",an[cu++]);}printf("= %d",n);}else printf("Impossible\n");return 0;
}

转载于:https://www.cnblogs.com/zhangchengc919/p/5400692.html

codeforces 664B B. Rebus(乱搞题)相关推荐

  1. POJ 1654 乱搞题?

    题意: 从一个点出发,8个方向,给出每一步的方向,求出走过的路径形成的多边形的面积. 思路: 先普及一下向量叉乘.. (摘自度娘) 也就是x1y2-x2y1. 那这不就好说了嘛. 一个经过原点的闭合多 ...

  2. 【bitset乱搞】BZOJ3687 简单题

    题面在这里 最喜欢这种乱搞题了 因为异或两次就等于没有异或 所以只需要记录不同算术和的奇偶即可 用一个bitset存 假设已经统计好了前面一部分算术和,新加一个x 那么每个数加x或不加,新的bitse ...

  3. 【BZOJ1999】树网的核,求树的直径+单调队列乱搞

    传送门 思路: 很好的一道乱搞题 原来的题目我写的是O(n3)O(n^3)的 由于n<=500000 所以我们可以猜一些结论来减少时间复杂度 比如说每个直径都有最小偏心距,直径上每个点的偏心距可 ...

  4. [STL乱搞]51 Nod——1573 美丽的集合

    [STL乱搞]51 Nod--1573 美丽的集合 题目梗概 在多重集之中,同一个元素可以出现多次. 我们现在有n个多重集合,第i个集合最开始都有一个元素ai(1≤i≤n). 定义多重集合的价值为子集 ...

  5. CodeForces - 747D Winter Is Coming(xjb乱搞)

    题目链接:http://codeforces.com/problemset/problem/747/D点击打开链接 D. Winter Is Coming time limit per test 1 ...

  6. 【CodeForces - 349A】Cinema Line (贪心(其实不是贪心),乱搞)

    题干: The new "Die Hard" movie has just been released! There are n people at the cinema box ...

  7. 【CodeForces - 569B】Inventory (标记,乱搞)

    题干: Companies always have a lot of equipment, furniture and other things. All of them should be trac ...

  8. bzoj 1050: [HAOI2006]旅行comf(codevs.cn 1001 舒适的路线) 快排+并查集乱搞

    没用的话:好像很久没发博客了,主要是懒太蒟找不到水题.我绝对没弃坑...^_^ 还用些话:本文为博主原创文章,若转载请注明原网址和作者. 进入正题: 先pa网址: bzoj :http://www.l ...

  9. codeforces1496 D. Let‘s Go Hiking(乱搞+讨论)

    这题我tm服了,考试中途肯定添加了一组数据,提交完A了之后,还有20min结束,感觉写不了下一个题了,就下班了,谁知道它有填了一组测试数据把我的乱搞给卡过去了,我又被fst了???然后我有乱改了一下又 ...

最新文章

  1. 我和大师Jeffrey Richter相约@北京
  2. Selenium3自动化测试——6.键盘操作
  3. 使用ansible安装docker以及docker-compose
  4. vs2005制作安装包(自动安装.net framework 2.0)(小寿原创)
  5. 使用远程工具连接提示**Host *** is not allowed to connect to this mysql server**拒绝连接错误
  6. linux 运行jupyter,在 Linux 上安装并运行 Jupyter
  7. sharding-jdbc水平分库与垂直分库
  8. PHP学习总结(13)——PHP入门篇之常量
  9. SQL Server中的文件流
  10. python登录微信pc版_详解PC端微信扫码注册和登录实例代码
  11. 163邮箱苹果设置不成功_iphone手机,苹果手机如何登陆网易163邮箱
  12. Java数据结构与算法
  13. 进制转换(八进制小数转十进制小数)
  14. CHUA 返回的矢量的长度为 3,但初始条件矢量的长度为 4。CHUA 返回的矢量和初始条件矢量的元素数目必须相同。
  15. 四级网络工程师试题九
  16. 华为路由器显示连接到服务器失败怎么办,华为路由WS5200可以搜到wifi但无法连接怎么办...
  17. 阿里云服务器如何搭建MQTT服务器
  18. 奥的斯电梯服务器自动呼梯,奥的斯外呼电梯控制系统说明
  19. 无线网突然提示IP地址冲突,无法连接
  20. 高分辨率屏电脑 centos虚拟机屏幕使字体变大的方法

热门文章

  1. tnsname.ora 个参数解释
  2. springMVC结合jersey实现跨服务器文件上传
  3. mysql运用实例_mysql应用实例
  4. android源码编译出错的原因
  5. f77编程和c语言的区别,在fortran中l用F77编译器编译程序时出现问题?
  6. signature=fc89d4352b6699754c14ce282ec75426,Broken chiral symmetry on a null plane
  7. dojo中chart参数
  8. Spring中都用到了哪些设计模式
  9. ShoeBox一个超级好用的图片切割工具
  10. JAVA基础之列表(list)和字典(dict)