codeforces 664B B. Rebus(乱搞题)
题目链接:
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,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(乱搞题)的更多相关文章
- CF_402C Searching for Graph 乱搞题
题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...
- 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 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- Codeforces 1077E (二分乱搞或者dp)
题意:给你一个数组,可以从中选区若干种元素,但每种元素选区的个数前一种必须是后一种的2倍,选区的任意2种元素不能相同,问可以选取最多的元素个数是多少? 思路1(乱搞):记录一下每种元素的个数,然后暴力 ...
- 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 ...
- HDU5764 After a Sleepless Night 树形乱搞题
分析(官方题解): 假设根已确定,可以发现新树若合法,需满足以下性质:根节点是n:儿子的值不大于父亲:具有相同值的节点形成一条链,并且链不会发生“分叉”(即有多个最低点).所以对于新树中有出现的值x, ...
- AT2386 Colorful Hats (乱搞题,思维题)
分情况讨论的神题... max不等于min + 1 或者不等于min,这种情况显然不存在. 如果都等于一个数 有两种情况: 互相独立,那么a[i]肯定==n-1 有相同的,那么a[i]一定不是独立的. ...
- 【16.05%】【codeforces 664B】Rebus
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- hihocoder 1236(2015北京网络赛 J题) 分块bitset乱搞题
题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...
随机推荐
- 启动weblogic域不需要输入密码设置方法
分类: IT综合技术 一.问题描述与分析 部署完WEBLOGIC后,在每次启动时执行./startWebLogic.sh脚本时,都会停在输入用户名与密码这里,相当不方便.所以要做到启动过程不输 ...
- AngularJS的Foreach循环示例
代码下载:https://files.cnblogs.com/files/xiandedanteng/angularJSForeach.rar 代码: <!DOCTYPE HTML PUBLIC ...
- HeadFirst设计模式 之 C++实现(三):Decorator(装饰者模式)
装饰者模式是非常有意思的一种设计模式,你将可以在不改动不论什么底层代码的情况下.给你的(或别人的)对象赋予新的职责. 不是使用继承每回在编译时超类上改动代码,而是利用组合(composition)和托 ...
- vue2.0 + vux (二)Footer组件
1.Footer组件 Footer.vue <!-- 底部 footer --> <template> <div> <tabbar> <!-- 综 ...
- C和C++代码精粹笔记1
CH1 更好的C 运算符重载规定,必须有一个为用户自定义类型 一些输出没注意到的函数: float x = 123.456, y = 12345; //cout.precision(2); //显示两 ...
- bootstrap到底是用来做什么的(概念)
Bootstrap官网:http://v3.bootcss.com/ Bootstrap是Twitter推出的一个用于前端开发的开源工具包.它由Twitter的设计师Mark Otto和Jacob T ...
- C#使用WebBrowser对指定网页截图
使用webbrowser获取html,然后输出的位图即可. WebBrowser wb = new WebBrowser(); // 创建一个WebBrowser wb.ScrollBarsEnabl ...
- mini2440使用jlink烧写superboot到norflash
Jlink版本号:J-flash ARM V4.12 J-Flash ARM的配置. 一般说来file-->open project里面会找到一些*.jfl ...
- 小printf的故事:什么是真正的程序员?
http://kb.cnblogs.com/page/570194/ 作者: 削微寒 来源: 博客园 发布时间: 2017-06-06 10:03 阅读: 33004 次 推荐: 98 原 ...
- 果壳、推库、虎秀、知乎、it世界
果壳.推库.虎秀.知乎.it世界