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乱搞题
题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...
随机推荐
- cacti监控linux和windows磁盘IO
cacti监控linux和windows磁盘IO 标签:cacti linux磁盘IO windows磁盘IO 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则 ...
- [Algorithm] Linked List Data Structure in JavaScript
A linked list is a collection of items where each item points to the next one in the list. Because o ...
- Git 常用场景操作
git init 在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹. git clone 获取一个u ...
- 微信授权网页登陆,oauth
1.在微信公众号请求用户网页授权之前.开发人员须要先到公众平台官网中的开发人员中心页配置授权回调域名.请注意,这里填写的是域名(是一个字符串),而不是URL,因此请勿加http://等协议头. 2.授 ...
- Vue 字面量语法 vs 动态语法
初学者常犯的一个错误是使用字面量语法传递数值: <!-- 传递了一个字符串 "1" --> <comp some-prop="1">&l ...
- 配置Office Outlook 2013
导航 背景——配置过程——错误(Error)——参考资料 背景 最近,折腾了一阵子邮箱客户端,包括:Foxmail.thuderbird.outlook:最后,考虑到outlook对文本的强大的支持能 ...
- C#编译器选项(目标平台)
用vs编译C#项目的设置中,“属性-生成-目标平台”有anycpu,x86,x64等选项. anycpu(默认值)将编译程序集为使其在任意平台上都可以运行. 在任何可能的时候,应用程序作为 64 位进 ...
- MySQL提示Access denied for user ''@'localhost'”的解决
记得那时由于没有网络,把rootpassword改错了写成了: update user set password="122" where user="root" ...
- kubernetes之初始容器(init container)
系列目录 理解初始容器 一个pod里可以运行多个容器,它也可以运行一个或者多个初始容器,初始容器先于应用容器运行,除了以下两点外,初始容器和普通容器没有什么两样: 它们总是run to complet ...
- 简单的HTML5音乐播放器(带歌词滚动)
// // 0) { this.lrcArr.push(item); } } frag = document.createDocumentFragment(); for(i = 0,len = t ...