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 ...
随机推荐
- powershell: 生成随机字符串
ASCII范围内的 获取6个随机字符(字母和数字) 48到57是数字0-9,powershell的范围操作符是..,和Perl 5的一样, 所以 48..57就是指(48 49 50 51 52 53 ...
- javaWeb el表达式和jstl快速入门案例
<%@page import="de.bvb.domain.Person"%> <%@page import="de.bvb.domain.Addres ...
- Linux中变量#,#,@,0,0,1,2,2,*,$$,$?的含义【转】
转自:http://www.cnblogs.com/kaituorensheng/p/4002697.html 1 2 3 4 5 6 7 8 $# 是传给脚本的参数个数 $0 是脚本本身的名字 $1 ...
- zjtd 2016面试
1.写一个函数get_next() class A{ public :int next(); //取下一个值,并且指针后移 bool has_next(); private: //可以认为是一个q ...
- eclipse内置tomcat启动方法
tomcat:run -Dmaven.tomcat.port=
- js里的匿名函数 数组排序
// 匿名函数:其实就是函数的简写形式 var method =function(){ alert("123"); } method(); // 匿名函数可以用于事件的处理 fun ...
- SQL中char、varchar、nvarchar的区别
char char是定长的,也就是当你输入的字符小于你指定的数目时,char(8),你输入的字符小于8时,它会再后面补空值.当你输入的字符大于指定的数时,它会截取超出的字符. nvarcha ...
- hihoCoder 数论五·欧拉函数
题目1 : 数论五·欧拉函数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho有时候会用密码写信来互相联系,他们用了一个很大的数当做密钥.小Hi和小Ho约定 ...
- css select 样式列表-----另一种样式列表
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org ...
- laravel 重写以及500错误
http://www.golaravel.com/laravel/docs/5.1/ sudo chmod 755 -R laravel chmod -R o+w laravel/storage