1193 Eason
Eason
| Acceteped : 57 | Submit : 129 | |
| Time Limit : 1000 MS | Memory Limit : 65536 KB |
Description |
||
题目描述Eason是个非常迷信的人,他喜欢数字3和6,不喜欢4和7。 如果一个数字的数码中没有4和7,而有3或者6的话,他就会喜欢这个数字。 比如,他会喜欢13,36,但是不会喜欢14,34。但对于28这种的,他就无所谓喜欢还是不喜欢。 Eason想知道区间[a,b]中一共有多少个他喜欢和不喜欢的数字? 输入每行输入一个样例,为a和b,0≤a≤b≤106。如果a和b都为0,那么输入结束,这个样例不需要处理。 输出每行输出一个样例的结果,先输出喜欢数字的个数,再输出不喜欢数字的个数。 样例输入1 10 样例输出2 2 |
||
Sample Input |
||
Sample Output |
||
Source |
解题:暴力或者数位dp乱搞
先上暴力的解法:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
int ans[],uu[];
void go(int dep,int cur,int step,bool like,bool ulike){
if(step > dep || like && ulike) return;
ans[cur] = like;
if(!like && !ulike) uu[cur] = ;
for(int i = step?:; i <= ; ++i)
go(dep,cur*+i,step+,like||i == ||i == ,ulike||i == ||i == );
}
int main(){
go(,,,false,false);
uu[] = ;
for(int i = ; i < ; ++i){
ans[i] += ans[i-];
uu[i] += uu[i-];
}
int a,b;
while(scanf("%d %d",&a,&b),a||b){
int tmp = ans[b]-ans[a-];
printf("%d %d\n",tmp,(b-a+)-(uu[b]-uu[a-])-tmp);
}
return ;
}
写得比较挫,很多冗余计算。。。后来改了下,起码好看得多了
#include <cstdio>
int ans[],uu[],arr[] = {,,,,,,,},a,b;
bool check[] = {false,false,false,true,false,true};
void go(int dep,int cur,int step,bool like){
if(step > dep) return;
if(like) ans[cur] = ;
else uu[cur] = ;
for(int i = step?:; i < ; ++i)
go(dep,cur*+arr[i],step+,like||check[i]);
}
int main(){
go(,,,false);
uu[] = ;
for(int i = ; i < ; ++i){
ans[i] += ans[i-];
uu[i] += uu[i-];
}
while(scanf("%d %d",&a,&b),a||b){
int tmp = ans[b]-ans[a-];
printf("%d %d\n",tmp,(b-a+)-(uu[b]-uu[a-])-tmp);
}
return ;
}
然后是数位dp
#include <cstdio>
#include <cstring>
int dp[][];
void calc(char *str,int &x,int &y){
bool xh = false,bxh = false;
int len = strlen(str);
static const int cnt[] = {,,,,,,,,,};
static const int cnt2[] = {,,,,,,,,,};
for(int i = x = y = ; str[i+]; ++i){
int p = (str[i] > '') + (str[i] > '');
if(!bxh){
if(xh) x += cnt[str[i]-'']*(dp[len-i-][]+dp[len-i-][]);
else{
x += cnt[str[i]-'']*dp[len-i-][] + p*dp[len-i-][];
y += cnt2[str[i]-'']*dp[len-i-][];
}
}
if(str[i] == '' || str[i] == '') bxh = true;
if(str[i] == '' || str[i] == '') xh = true;
}
for(int i = ; i <= str[len-]-''; ++i){
if(!xh && !bxh &&(i == || i == )) ++x;
if(xh && !bxh && i != && i != ) ++x;
if(!bxh && !xh && i != && i != && i != && i != ) ++y;
}
}
int main(){
dp[][] = ;
dp[][] = ;
for(int i = ; i <= ; ++i){
dp[i][] = (dp[i-][]<<) + (dp[i-][]<<);
dp[i][] = *dp[i-][];
}
char str[];
int a,b;
while(scanf("%d %d",&a,&b),a||b) {
int x,y,x1,y1;
sprintf(str,"%d",--a);
calc(str,x,y);
sprintf(str,"%d",b);
calc(str,x1,y1);
int tmp = x1 - x;
printf("%d %d\n",tmp,b-a-tmp-y1+y);
}
return ;
}
1193 Eason的更多相关文章
- bzoj 1193 贪心
如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
- bzoj 1193
http://www.lydsy.com/JudgeOnline/problem.php?id=1193 大范围贪心,小范围宽搜. 膜拜大神 http://blog.csdn.net/u0129155 ...
- bzoj 1193 贪心+bfs
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2015 Solved: 914[Submit][Statu ...
- 1193: [HNOI2006]马步距离
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2027 Solved: 915[Submit][Statu ...
- 九度OJ 1193:矩阵转置 (矩阵计算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1673 解决:1132 题目描述: 输入一个N*N的矩阵,将其转置后输出.要求:不得使用任何数组(就地逆置). 输入: 输入的第一行包括一个 ...
- BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...
- hpuoj 1193: Interval
Interval [STL.双指针.二分] 题目链接 http://acm.hpu.edu.cn/problem.php?id=1193 或者 题目链接 http://acm.nyist.net/Ju ...
- Vijos 1193 扫雷 【动态规划】
扫雷 描述 相信大家都玩过扫雷的游戏.那是在一个n*n的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”任过流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没有雷,那么它 ...
- JOBDU 1193 矩阵转置
啊!!!这道题目今天竟然写错了!!!这道题目巨坑,说不能用数组,结果竟然是用数组做的,吐血!!! 看的所有有关博文,都是用数组做的,晕倒!真的出题人有毛病,出这种题,又不限制运行!!! 以后再遇到这种 ...
随机推荐
- js效果之导航中英文转换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- vue 锚点定位
vue 锚点定位 <template> <div class="details"> <div class="wrapper w"& ...
- GET,POST请求
get请求 post请求
- div隐藏但是依然占位置
<!doctype html> <html> <head> <meta charset="utf-8"> <script ty ...
- CF939F Cutlet (单调队列优化DP)
题目大意:要煎一块有两个面的肉,只能在一段k不相交的时间段$[l_{i},r_{i}]$内翻转,求$2*n$秒后,保证两个面煎的时间一样长时,需要最少的翻转次数,$n<=100000$,$k&l ...
- python yield 生成器的介绍(转载)
您可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ? 我们先抛开 generator,以一个常见的编程题目来展示 yield ...
- 抓取豆瓣的电影排行榜TOP100
#!/usr/bin/env python # -*- coding:utf-8 -*- """ 一个简单的Python爬虫, 用于抓取豆瓣电影Top前100的电影的名称 ...
- 题解 P3128 【[USACO15DEC]最大流Max Flow】
此类型题目有两种比较常见的做法:树链剖分和树上差分. 本题有多组修改一组询问,因此树上差分会比树链剖分优秀很多. 这里两种方法都进行介绍. 树链剖分和树上差分的本质都是将一颗树转换为一个区间,然后进行 ...
- 【Henu ACM Round#24 B】Gargari and Bishops
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果写过n皇后问题. 肯定都知道 某个点(i,j)和它在同一条对角线上的点分别是i+j的值和i-j的值相同的点. 然后会发现选择的两 ...
- 普通码农和CTO之间的差距
虚心 学习的第一步是--"我不懂".一个空是水杯才能装水,如果是满的就没有办法装水了."自我肯定"是一种非常难克服的习惯,经常会有朋友看到某个技术或者实现之后不 ...