Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分
1 second
256 megabytes
standard input
standard output
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
The first line of the input contains integer n (1 ≤ n ≤ 105) — the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers — a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
3
?
18
1?
YES
1
18
19
2
??
?
NO
5
12224
12??5
12226
?0000
?00000
YES
12224
12225
12226
20000
100000
题意:给你n个数,但是有些数字不知道,需要你填写,使得最后的序列为一个严格递增的序列
思路:一个二分,但是这个二分很特别,刚刚开始想,二分这个数,使得最小满足大于上一个数,
也满足给你那个数的原来的那些数,但是发现不好写,转化一下,把原来给的数剔除掉,
把那些问号拼凑成一个数,二分问号的这个数,然后分开填进去看是否满足;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+,MOD=1e9+;
char a[N][],b[];
int c[];
int ans[N];
int check(int x,int pos)
{
int len=strlen(a[pos]);
for(int i=;i<len;i++)
b[i]=a[pos][i];
for(int i=len-;i>=;i--)
{
if(b[i]=='?')
{
b[i]=x%+'';
x/=;
}
}
int ans=;
for(int i=;i<len;i++)
ans=ans*+b[i]-'';
return ans;
}
int lower(int x,int pos)
{
int flag=;
int st=;
int en=;
int ans=-;
for(int i=;i<strlen(a[pos]);i++)
{
if(a[pos][i]=='?')
flag++,en*=;;
}
if(a[pos][]=='?')
st=en/;
en--;
while(st<=en)
{
int mid=(st+en)>>;
//cout<<mid<<" "<<check(x,pos)<<" "<<x<<" "<<endl;
if(check(mid,pos)>x)
{
ans=mid;
en=mid-;
}
else
st=mid+;
}
if(ans==-)
return -;
for(int i=strlen(a[pos])-;i>=;i--)
{
if(a[pos][i]=='?')
{
a[pos][i]=ans%+'';
ans/=;
}
}
int sum=;
for(int i=;i<strlen(a[pos]);i++)
sum=sum*+a[pos][i]-'';
return sum;
}
int main()
{ int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%s",&a[i]);
int pre=;
for(int i=;i<=n;i++)
{
ans[i]=lower(pre,i);
if(ans[i]==-)
return puts("NO\n");
pre=ans[i];
}
printf("YES\n");
for(int i=;i<=n;i++)
{
printf("%d\n",ans[i]);
}
return ;
}
Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分的更多相关文章
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #279 (Div. 2) 题解集合
终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- 【Codeforces Round#279 Div.2】B. Queue
这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...
- Codeforces Round #279 (Div. 2) B. Queue
B. Queue time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #279 (Div. 2) vector
A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀
C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces Round #279 (Div.2)
A: 题意: 有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍. 分析: 最多能组成的队伍的个数就是擅长项目里的最少学生. #i ...
随机推荐
- mysql单表查询&&多表查询(职员表14+9)
dept(deptno,dname,loc) emp(empno,ename,job,mgr,hiredate,sal,COMM,deptno) salgrade(grade,losal,hisal) ...
- VMware中安装CentOS7网络配置静态IP地址,常用配置和工具安装
VMware中安装CentOS7网络配置静态IP地址,常用配置和工具安装在阿里云开源镜像地址下载镜像Index of /centos/7.2.1511/isos/x86_64/http://mirro ...
- #import vs. @class
You #import or #include when there is a physical dependency. Otherwise, you use forward declarations ...
- [转]System.Reflection.AssemblySignatureKeyAttribute
转自:http://www.cnblogs.com/ego/p/3321122.html 错误: Could not load type 'System.Reflection.AssemblySign ...
- Hadoop集群管理之内存管理
1.内存 Hadoop为各个守护进程(namenode,secondarynamenode,jobtracker,datanode,tasktracker)统一分配的内存在hadoop-env.sh中 ...
- 启动hadoop报192.168.1.151: Address 192.168.1.151 maps to node1, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
使用root用户启动hadoop的时候报错: [root@node1 ~]# su - hadoop -c start-all.sh starting namenode, logging to /ap ...
- Mysql数据库知识-Mysql索引总结 mysql mysql数据库 mysql函数
mysql数据库知识-Mysql索引总结: 索引(Index)是帮助MySQL高效获取数据的数据结构. 下边是自己整理的资料与自己的学习总结,,做一个汇总. 一.真的有必要使用索引吗? 不是每一个性能 ...
- html 和 html5(一)(表格 | 列表 | 提交按钮 | 单选 |复选 | 框架 | 脚本 | html字符实体 )
一.框架 使用iframe来显示目录链接页面 iframe可以显示一个目标链接的页面 目标链接的属性必须使用iframe的属性,如下实例: 实例 <iframe src="demo_i ...
- JAVA基础知识之Collections工具类
排序操作 Collections提供以下方法对List进行排序操作 void reverse(List list):反转 void shuffle(List list),随机排序 void sort( ...
- Callable, Runnable, Future, FutureTask
Java并发编程之Callable, Runnable, Future, FutureTask Java中存在Callable, Runnable, Future, FutureTask这几个与线程相 ...