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乱搞题
题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...
随机推荐
- 正确使用Block避免Cycle Retain和Crash
Block简介 Block作为C语言的扩展,并不是高新技术,和其他语言的闭包或lambda表达式是一回事.需要注意的是由于Objective-C在iOS中不支持GC机制,使用Block必须自己管理内存 ...
- DAO 层实现
一.实验介绍 1.1 实验内容 本节课程主要利用 MyBatis 框架实现 DAO 层. 1.2 实验知识点 MyBatis 框架 MySQL 1.3 实验环境 JDK1.8 Eclipse Java ...
- Lazarus安装使用
Lazarus安装使用 最后还是安装了Lazarus: 安装之后,新建了项目,还引入了Unit,就可以跑了: 学习:http://tieba.baidu.com/p/3164001113 progra ...
- UVA 12338 - Anti-Rhyme Pairs(后缀数组+RMQ)
UVA 12338 - Anti-Rhyme Pairs 题目链接 题意:给定一些字符串,每次询问求出两个字符串的最长公共前缀的长度 思路:把字符串排序,就能求出height和rank数组,然后利用R ...
- xammp 配置虚拟主机
## This is the main Apache HTTP server configuration file. It contains the# configuration directives ...
- PHP ORM操作MySQL数据库
ORM----Oriented Relationship Mapper,即用面向对象的方式来操作数据库.归根结底,还是对于SQL语句的封装. 首先,我们的数据库有如下一张表: 我们希望能够对这张表,利 ...
- 最新研发的基于Java的高速开发平台
可自我扩展的智能开发平台 在开发平台设计过程中,联科研发部一開始就希望能研发一套智能开发机制能自己开发自己的平台-即一个能自我修复和自我扩展的开发平台.这个开发平台不但能开发其它应用还能不 ...
- 7.2 HAVING子句
7.2 HAVING子句正在更新内容.请稍后
- Laravel建站01--开发环境部署
内容导航 安装git 安装composer 安装Laravel 既然是开发环境,就需要源代码管理.这里使用git来管理. 一:部署开发环境之前安装git 在 Linux 上安装git 如果你想在 Li ...
- tree related problems (update continuously)
leetcode Binary Tree Level Order Traversal 这道题是要进行二叉树的层次遍历.对于层次遍历,最简单直观的办法就是进行BFS.于是我们仅仅须要维护一个队列就能够了 ...