Codeforces Round #347 (Div. 2) B. Rebus
题目链接:
http://codeforces.com/contest/664/problem/B
题意:
给你一个等式,把等式左边的问号用1到n(n为等式右边的数)的数填好,使得等式成立
题解:
贪心求出最小最大值,如果n在这个范围则有解,否则无解。
构造解: 取最小值或最大值,然后从第一个数开始调整,直到等式成立为止。
代码:
#include<iostream>
#include<cstring>
#include<vector>
using namespace std; const int maxn = ;
const int INF = 1e9 + ; char str[maxn], sig[maxn];
int val[maxn],p1,p2;
int n; void init() {
p1 = , p2 = ;
sig[p1++] = '+';
} int main() {
init();
while (scanf("%s", str) == && str[] != '=') {
if (str[] == '?') { }else{
sig[p1++] = str[];
}
}
sig[p1] = '\0';
scanf("%d", &n);
int mi=, ma=;
vector<int> ans;
for (int i = ; i < p1; i++) {
if (sig[i] == '+') mi += ,ma+=n,ans.push_back();
else mi -= n,ma-=,ans.push_back(n);
}
if (n >= mi&&n <= ma) {
int dis = n-mi;
for (int i = ; i < p1; i++) {
if (sig[i] == '+') {
if (dis >= n - ) {
ans[i] = n;
dis -= (n - );
}
else {
ans[i] += dis;
dis = ;
}
}
else {
if (dis >= n - ) {
ans[i] = ;
dis -= (n - );
}
else {
ans[i] -= dis;
dis = ;
}
}
if (dis == ) break;
}
printf("Possible\n");
for (int i = ; i < p1-; i++) {
printf("%d %c ", ans[i], sig[i + ]);
}
printf("%d = %d\n", ans[p1 - ], n);
}
else {
printf("Impossible\n");
}
return ;
}
Codeforces Round #347 (Div. 2) B. Rebus的更多相关文章
- Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...
- Codeforces Round #347 (Div. 2)
unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- Codeforces Round #347 (Div.2)_A. Complicated GCD
题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...
- Codeforces Round #347 (Div. 2) (练习)
A: 题意:找到[a, b]的最大公约数: 思路:相同时为本身,不同时为1. 套路:碰到水题别想太多: 猜想:两个相邻数,必有一奇一偶,如果偶数有因子3或者其他,奇数可不可能有相同的呢? 枚举一些数后 ...
- codeforces Round #347 (Div. 2) C - International Olympiad
思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...
- Codeforces Round #347 (Div. 2) A
Description Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the bigge ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- ASP.Net 获取当前时间,包含各种时间格式
在c# / ASP.net中我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04).时间(12:12:12).日期+时间 ...
- jquery实现多行文字图片滚动效果
今儿分享一个jquery实现多行滚动效果. 我看一些论坛网站上面,公告处用的较多. 代码如下 复制代码 // 多行滚动(function($){$.fn.extend({Scroll:function ...
- 6步图文教你优化myeclipse2014
MyEclipse 2014优化速度方案仍然主要有这么几个方面:去除无需加载的模块.取消冗余的配置.去除不必要的检查.关闭更新. 第一步: 去除不需要加载的模块 一个系统20%的功能往往能够满足80% ...
- Swiper API
本文分享自 http://www.cnblogs.com/scavengers/p/3760449.html 最近使用Swipe.js,发现中文的资料很少,试着翻译了一下.能力有限,翻译难免错漏,欢迎 ...
- Android实现Http协议案例
在Android开发中,使用Http协议实现网络之间的通信是随处可见的,使用http方式主要采用2中请求方式即get和post两种方式. 一.使用get方式: HttpGet httpGet = ne ...
- 比较不错的一个ios找茬游戏源码
找茬游戏源码 ,这个是一款非常不错的ios找茬游戏源码,该游戏的兼容性非常好的,并且还可以支持ipad和iphone,UI界面设计得也很漂亮,游戏源码真的是一款非常完美,而且又很完整的一款休闲类的游戏 ...
- EDK中如何使用ISE中生成的IP
EDK中如何使用ISE中生成的IP: 网上上有说这个的文章,但是很复杂,也就是添加bdd文件,其实这些都不需要自己操作的,我们可以在EDK中import 中添加ngc文件,ngc文件就是core ge ...
- vmware虚拟机上网:NAT搭建局域网
若是你不知道的情况下,可以编辑虚拟机网络配置,然后恢复默认,vmware会自动给你分配好ip,默认使用的是vmware8,下面的是使用默认的配置 看图 注意:子网的ip一定要在如上图所示的范围 适配器 ...
- ASP.NET Core 1.0
.NET Core dotnet 命令大全:http://www.cnblogs.com/linezero/p/dotnet.html http://www.cnblogs.com/Wddpct/p/ ...
- postgresql 开启远程访问
1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...