题目链接:

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. maven打包自动配置数据库链接信息

    pom.xml加入下面代码 <profiles> <profile> <id>dev</id> <activation> <activ ...

  2. 阿里云云服务器ubuntu配置nginx+uwsgi+django记录文档

    1 安装ssh 1  sudo apt-get update 2  sudo apt-get install openssh-server 3  sudo ps -e |grep ssh  有sshd ...

  3. 采用scp命令在Linux系统之间copy文件

    不同的Linux之间copy文件常用有3种方法,第一种就是ftp,也就是其中一台Linux安装ftp Server,这样可以另外一台使用ftp的client程序来进行文件的copy.第二种方法就是采用 ...

  4. sql的一些知识_高级

    1.视图 http://www.cnblogs.com/wang666/p/7885934.html 2.存储过程 http://www.cnblogs.com/wang666/p/7920748.h ...

  5. 百度地图SDK调试SDKInitializer.initialize(getApplicationContext())错误

    首先描写叙述下问题出现的原因.開始的时候写了一个百度地图SDK的demo来试功能,由于最開始用的是Eclipse自带的AVD来调试,一切正常. 都能够正常验证,可是由于受不了重复的重新启动AVD设备, ...

  6. 对OpenCV中Haar特征CvHaarClassifierCascade等结构理解

    首先说一下这个级联分类器,OpenCV中级联分类器是根据VJ 04年的那篇论文(Robust Real-Time Face Detection)编写的,查看那篇论文,知道构建分类器的步骤如下: 1.根 ...

  7. java stoi

    package string.string1_4; import java.util.Scanner; public class StrToInt { /** * 将str转换为int整数 * 1. ...

  8. python pyinotify模块详解

    转载于http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=23504396&id=2929446 1年多前就看过相关内容了, ...

  9. CSS入门学习

    一.What? CSS的全称是CascadingStyle Sheet,汉语意思是"级联样式表".通常又称为"风格样式表(StyleSheet)".它是用来进行 ...

  10. Appium python自动化测试系列之Capability介绍(五)

    ​5.1 Capability介绍 5.1.1 什么是Capability 在讲capability之前大家是否还记得在讲log时给大家看过的启动时的日志?在我们的整个启动日志中会出现一些配置信息,其 ...