这题说的是给了一个数在longlong范围内 然后求出小于这个数的最大的回文,枚举每位减去1后 , 他后面的位置上全部都置为9,然后在枚举每个前半部分,然后贪心取得这个数的最大值,贪心的时候写错了,错在这..到枚举到now[loc]<now[loc+1] 时 就进行下一位,但是下一位不可能取得的时候却没有继续枚举这一位较小的

#include <cstdio>
#include <string.h>
#include <algorithm>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX_N = ;
ll str[MAX_N];
ll now[MAX_N],N,E[MAX_N],ans;
int perLen,nowLen;
void reserve(ll *C,int len){
for(int i=; i<len/; i++){
ll c = C[i];
C[i]=C[len-i-];
C[len--i]=c;
}
}
void uniquet(ll *C, int &len){
int now =;
for(int i=; i<len; i++){
if(C[i]!=C[now-]){
C[now++]=C[i];
}
}
len=now;
}
bool dfs(int loc1, int loc2, ll R)
{
if(loc2==perLen){
if(loc1==nowLen){
ans=ans>R?ans:R; return true;
}
return false;
}
if(loc1==nowLen) return false;
ll cur = R+now[loc1]*E[perLen-loc2-];
if(cur>=N) return false;
bool ans=false;
if(now[loc1]>now[loc1+]&&nowLen - loc1 < perLen - loc2){
ans= dfs(loc1,loc2+,cur);
}
if(ans==true) return true;
ans=dfs(loc1+,loc2+,cur);
if(ans==false) ans=dfs(loc1,loc2+,cur);
return ans;
}
void solve()
{
for(int i =; i<perLen; i++){
ll R =; nowLen=;
for(int j=; j<=i; ++j ){
R=R+str[j]*E[perLen--j];
now[nowLen++]=str[j];
}
uniquet(now,nowLen);
reserve(now,nowLen);
now[nowLen]=-;
dfs(,i+,R);
nowLen=;
if(i==) continue;
for(int j=; j<i; ++j ){
now[nowLen++] = str[j];
}
uniquet(now,nowLen);
reserve(now,nowLen);
now[nowLen]=-;
dfs(,i+,R);
}
}
int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int cas;
E[]=;
for(int i=; i<=; i++)
E[i]=E[i-]*10LL;
scanf("%d",&cas);
while(cas--){
scanf("%lld",&N);
if(N<){
if(N==) {
puts("");
}
else {
printf("%lld\n",N-);
}
continue;
}
int len=;
ll we = N;
while(we>){
len++; we/=;
}
ans=;
for(int i=; i< len; ++i){
ll to = N-E[i];
perLen = ;
for(int j = ; j<i; j++){
str[perLen++]=; to/=;
}
while(to){
str[perLen++]=to%;
to/=;
}
reserve(str,perLen);
solve();
}
printf("%lld\n",ans);
}
return ;
}

zoj3814的更多相关文章

随机推荐

  1. linux系统下网络主-备份策略之网卡bond技术

    操作系统:CentOS Linux release 7.1.1503 (Core) 网卡适配器: eno1.eno2 bonding类型:mode=1 (active-backup),主-备份策略 网 ...

  2. iOS uitextfield长度限制

    [textUsername addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEd ...

  3. python nose测试框架全面介绍九---各种html报告插件对比

    一直在使用Nose-html-reporting,并输出html报告,但今天在使用时发出有点问题:于时,将python目前可能的html报告插件下载后进行对比,如下 一.Nose-html-repor ...

  4. selenium下firefox自动下载配置及问题

    在做自动化测试时,需要从网页上下载相关的文件到指定的目录,一直未能实现 网上正好有个blog文章介绍了如何下载 直接上代码: from selenium import webdriver import ...

  5. oracle如何设置表空间autoextensible自动扩容

    SELECT a.tablespace_name "表空间名", total / 1024 / 1024 "表空间大小单位M", free / 1024 / 1 ...

  6. iOS - 处理计算精度要求很高的数据,floatValue,doubleValue等计算不精确问题

    .问题描述:服务器返回的double类型9...94的数字时 .之前处理方式是 :(从内存.cpu计算来说double都是比较合适的,一般情况下都用double) goodsPrice.floatVa ...

  7. jQuery将时间转化为时间戳或将时间戳转化为时间

    下面的这段代码,是可以将时间戳转为时间,或者将时间戳转为时间: <script type="text/javascript"> $.extend({ myTime:{ ...

  8. 7.18 python进程间数据共享

    # 管道# 数据共享 Manager# 进程池和回调函数 ! # !/usr/bin/env python # !--*--coding:utf-8 --*-- # !@Time :2018/7/18 ...

  9. 消息通讯之关于消息队列MQ必须了解的相关概念

    目录 系统通讯方式有哪些? 消息队列的应用场景 消息队列通讯模型 常见的消息协议 AMQP MQTT ATOMP JMS 小结 系统通讯方式有哪些? RPC调用 RPC 全称 Remote Proce ...

  10. 利用 background 和 filter 模糊指定区域

    背景知识:background-size: cover;,background-attachment:fixed;,filter:blur() 难题: 通常,我们会通过filter:blur()去实现 ...