题目链接:

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
Possible
9 + 13 - 39 + 28 + 31 = 42
input
? - ? = 1
output
Impossible
input
? = 1000000
output
Possible
1000000 = 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+;
typedef long long ll;
const int mod=1e9+;
char str[];
int ans[],an[];
int main()
{
int cnt=;
int num1=,num2=,n;
char s;
while()
{
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=;i<num1;i++)
{
ans[i]=;
}
int number=(num1-n)/num2;
for(int i=;i<num2;i++)
{
if(i<(num1-n)%num2)
an[i]=number+;
else an[i]=number;
} }
else if(num2-num1>n)
{
for(int i=;i<num2;i++)
{
an[i]=;
}
int number=(num2+n)/num1;
for(int i=;i<num1;i++)
{
if(i<(num2+n)%num1)ans[i]=number+;
else ans[i]=number;
}
}
else
{ int number=(n+num2)/num1;
for(int i=;i<num1;i++)
{
if(i<(n+num2)%num1)ans[i]=number+;
else ans[i]=number;
}
for(int i=;i<num2;i++)
{
an[i]=;
} }
printf("%d ",ans[]);
int cut=,cu=;
for(int i=;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 ;
}

codeforces 664B B. Rebus(乱搞题)的更多相关文章

  1. CF_402C Searching for Graph 乱搞题

    题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...

  2. codeforces 653C C. Bear and Up-Down(乱搞题)

    题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  4. Codeforces 1077E (二分乱搞或者dp)

    题意:给你一个数组,可以从中选区若干种元素,但每种元素选区的个数前一种必须是后一种的2倍,选区的任意2种元素不能相同,问可以选取最多的元素个数是多少? 思路1(乱搞):记录一下每种元素的个数,然后暴力 ...

  5. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  6. HDU5764 After a Sleepless Night 树形乱搞题

    分析(官方题解): 假设根已确定,可以发现新树若合法,需满足以下性质:根节点是n:儿子的值不大于父亲:具有相同值的节点形成一条链,并且链不会发生“分叉”(即有多个最低点).所以对于新树中有出现的值x, ...

  7. AT2386 Colorful Hats (乱搞题,思维题)

    分情况讨论的神题... max不等于min + 1 或者不等于min,这种情况显然不存在. 如果都等于一个数 有两种情况: 互相独立,那么a[i]肯定==n-1 有相同的,那么a[i]一定不是独立的. ...

  8. 【16.05%】【codeforces 664B】Rebus

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. hihocoder 1236(2015北京网络赛 J题) 分块bitset乱搞题

    题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...

随机推荐

  1. 邁向IT專家成功之路的三十則鐵律 鐵律十七:IT人休閒之道-清心

    現代人的休閒生活可說是兩類極端的表現,一類是整天待在家裡當個超級宅男宅女,假日走最遠的路就是附近三百公尺內的泡沫紅茶店.另一類則是抱著及時享樂心態的美女與型男,整天趴趴走把辛苦賺來的錢都拿去玩樂.美食 ...

  2. AndroidStudio怎样导入jar包

    来自:http://jingyan.baidu.com/article/e6c8503c7190b7e54f1a1893.html AndroidStudio用于开发安卓Apk非常地方便,但是它的很多 ...

  3. xpath的匹配规则

    starts-with 匹配一个属性开始位置的关键字 contains 匹配一个属性值中包含的字符串 text() 匹配的是显示文本信息,此处也可以用来做定位用 i.e. //input[starts ...

  4. Android API Guides---Services

    服务 在该文献 基础 声明在清单服务 创建一个启动的服务 扩展IntentService类 扩展服务类 启动服务 停止服务 创建绑定服务 将通知发送给用户 执行在前台服务 管理服务生命周期 实施生命周 ...

  5. 纯JS设置首页,增加收藏,获取URL參数,解决中文乱码

    雪影工作室版权全部,转载请注明[http://blog.csdn.net/lina791211] 1.前言 纯Javascript 设置首页,增加收藏. 2.设置首页 // 设置为主页 functio ...

  6. Windows 编程1

    杀死一个进程 使用命令 system( taskkill /f /im     QQ.exe); 即可. 打开一个进程 使用命令 system("应用程序的位置");   头文件: ...

  7. xcode 5.0 以上去掉icon高亮方法&amp;iOS5白图标问题

    之前的建议方法是把在xxx.info.plist文件里把 icon already includes gloss and bevel effects 设置YES 在Xcode5下,重复实现不成功,今天 ...

  8. Ubuntu下编译Poco库

    本文主要记录下Ubuntu下编译Poco C++库的配置项以备后用.系统版本:Ubuntu 16.04,1 Poco 版本:1.9.0基本的步骤如下: 1.从官网下载最新的Poco源码,地址是:htt ...

  9. spl_autoload_register的使用

    class Loader{ static function loadClass($class) { $class = $class.'.php'; if(file_exists($class)) { ...

  10. [Node.js] 關於 console.log 的格式化輸出

    Node.js 當中的 console.log,除了基本字串的輸出之外,還可以利用 %s.%d.%j 格式化的輸出,就讓我們來看些例子吧! 一.範例1 (字串輸出):console.js consol ...