题目链接:

ztr loves lucky numbers

 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
ztr喜欢幸运数字,他对于幸运数字有两个要求
1:十进制表示法下只包含4、7
2:十进制表示法下4和7的数量相等
比如47,474477就是
而4,744,467则不是 现在ztr想知道最小的但不小于n的幸运数字是多少
输入描述
有TT(1≤T≤10​5​​)组数据,每组数据一个正整数n,n<=10^18}1≤n≤10​^18​​
输出描述
有TT行,每行即答案
输入样例
2
4500
47
输出样例
4747
47 题意思路: 分情况讨论呗; AC代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+;
const LL mod=1e9+;
const double PI=acos(-1.0);
int a[],b[],vis1,vis2;
char s[];
int check(int x)
{
for(int i=;i<x/;i++)
{
if(b[i]<)return ;
else if(b[i]>)return ;
}
for(int i=x/;i<x;i++)
{
if(b[i]<)return ;
else if(b[i]>)return ;
else continue;
}
return ;
}
void print(int x1,int x2)
{
for(int i=;i<=x1;i++)printf("");
for(int i=;i<=x2;i++)printf("");
}
void print(int type)
{
if(type==)printf(""),vis1--;
else printf(""),vis2--;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",s);
if(s[]<''&&s[]>'')printf("");
else
{
int num=strlen(s);
for(int i=;i<num;i++)
b[i]=s[i]-'';
if(num&)
{
num++;
print(num>>,num>>);
}
else
{
if(!check(num))
{
num+=;
print(num>>,num>>);
}
else
{
vis2=vis1=(num>>);
for(int i=;i<num;i++)
{
if(b[i]>&&b[i]<)
{
print();
print(vis1,vis2);
break;
}
else if(b[i]==)print();
else if(b[i]<)
{
if(vis1)
{
print();
print(vis1,vis2);
break;
}
else
{
for(int j=;j<vis2;j++)printf("");
break;
}
}
else
{
LL ans1=,ans2=;
for(int j=;j<vis2+vis1-;j++)
{
if(j<vis2) ans1=ans1*+;
else ans1=ans1*+;
}
for(int j=i+;j<num;j++)ans2=ans2*+b[j];
if(ans2<=ans1&&vis1)print();
else
{
print();
print(vis1,vis2);
break;
}
}
}
}
}
}
printf("\n");
}
return ;
}

hdu-5676 ztr loves lucky numbers(乱搞题)的更多相关文章

  1. HDU 5676 ztr loves lucky numbers (模拟)

    ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...

  2. hdu 5676 ztr loves lucky numbers(dfs+离线)

    Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...

  3. hdu 5676 ztr loves lucky numbers 打表+二分

    ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  4. hdu 5676 ztr loves lucky numbers

    题目链接:hdu 5676 一开始看题还以为和数位dp相关的,后来才发现是搜索题,我手算了下,所有的super lucky number(也就是只含数字4, 7且4, 7的数量相等的数)加起来也不过几 ...

  5. HDU 5676 ztr loves lucky numbers【DFS】

    题目链接; http://acm.hdu.edu.cn/showproblem.php?pid=5676 题意: 由4和7组成的且4和7出现次数相同的数称为幸运数字,给定n,求不大于n的最大幸运数字. ...

  6. ztr loves lucky numbers 傻逼的我来了个大模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=5676 这题的正解因该是dfs的,但是有18个位,然后我一算,全排列的话,有18!个啊,那不是很大?但是有很多是相 ...

  7. hdu5676 ztr loves lucky numbers(dfs)

    链接 ztrloveslucky numbers 题意 定义幸运数为:只存在4和7且4和7数量相等的数,给出n,求比>=n的最小幸运数 做法 暴力搜出所有长度从2-18的幸运数,因为最多9个4, ...

  8. hdu 4112 Break the Chocolate(乱搞题)

    题意:要把一块n*m*k的巧克力分成1*1*1的单元,有两种操作方式:1,用手掰(假设力量无穷大),每次拿起一块,掰成两块小的:2,用刀切(假设刀无限长),可以把多块摆在一起,同时切开.问两种方式各需 ...

  9. HDU 5677 ztr loves substring(Manacher+dp+二进制分解)

    题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...

随机推荐

  1. PHP html_entity_decode() 函数

    html_entity_decode(string,flags,character-set) 把 HTML 实体转换为字符. html_entity_decode() 函数是 htmlentities ...

  2. echarts 图表用例

    参考博客:http://blog.csdn.net/verne_feng/article/details/51731653 http://echarts.baidu.com/echarts2/doc/ ...

  3. mysql获取子父级节点

    获取所有子节点 DROP FUNCTION IF EXISTS `F_Co29_GetAllChildrenIdsOfTaskevent`;DELIMITER //CREATE FUNCTION `F ...

  4. android 获得SDCard信息

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  5. fabricJs使用系列(一)

    Get the canvas object while using fabric js I'm using Fabric.js and I've created a fabric canvas obj ...

  6. [Javascript] Convert a Callback-Based JavaScript Function to a Promise-Based One

    Sometimes, you might want to convert a JavaScript function that accepts a callback to one that retur ...

  7. SolidEdge如何复制特征 建立类似于UG 块的概念

    直接Ctrl+C和Ctrl+V可以实现特征的复制粘贴   按N键可以改变特征方向 已经复制完成的特征要进行定位,则右击该特征,编辑轮廓,可以进行聪慧尺寸的标注   使用特征库的方式,就像UG的块一样, ...

  8. 自己定义控件事实上非常easy1/6

    尊重原创转载请注明:From AigeStudio(http://blog.csdn.net/aigestudio)Power by Aige 侵权必究! 炮兵镇楼 上一节我们粗略地讲了下怎样去实现我 ...

  9. leetcode 刷题之路 68 Gas Station

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  10. Eclipse - 循环cin的输出怎样终止

    循环cin的输出怎样终止 本文地址: http://blog.csdn.net/caroline_wendy Eclipse中, 使用CDT编写C++代码时, 循环(while)cin输入程序, 须要 ...