#299 (div.2) B. Tavas and SaDDas

1.题目描述:点击打开链接

2.解题思路:本题要求找出所给的幸运数的下标。本题类似于紫书上的一道例题ugly number。利用BFS即可解决。首先将4,7入队列,每次出队列后,将数字添加到set,同时将它们的末尾分别添加是4,7后得到新的幸运数入队列即可。上述过程打表后,直接输出即可。

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;

#define INF 100000000
#define For(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
const int N = 1000000000 + 5;
set<ll>a;

void init()
{
	int cnt = 1;
	queue<ll>q;
	q.push(4); q.push(7);
	while (!q.empty())
	{
		ll u = q.front(); q.pop();
		if (u > 1000000000)break;
		a.insert(u);
		ll u1 = u * 10 + 4, u2 = u * 10 + 7;
		q.push(u1);
		q.push(u2);
	}
}
int main()
{
	//freopen("t.txt", "r", stdin);
	ll n;
	init();
	while (~scanf("%I64d", &n))
	{
		set<ll>::iterator  it;
		it = a.find(n);
		cout << distance(a.begin(), it) + 1 << endl;
	}
	return 0;
}
时间: 2024-10-07 18:54:55

#299 (div.2) B. Tavas and SaDDas的相关文章

水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

题目传送门 1 /* 2 很简单的水题,晚上累了,刷刷水题开心一下:) 3 */ 4 #include <bits/stdc++.h> 5 using namespace std; 6 7 char s1[11][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven

DFS Codeforces Round #299 (Div. 2) C. Tavas and Karafs

题目传送门 1 /* 2 DFS:按照长度来DFS,最后排序 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11 12 const int MAXN = 1e3 + 10; 1

二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs

题目传送门 1 /* 2 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 3 二分搜索:搜索r,求出sum <= t * m的最大的r 4 详细解释:http://blog.csdn.net/libin56842/article/details/45082747 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #includ

Codeforces Round #299 (Div. 1)C. Tavas and Pashmaks (凸壳)

C. Tavas and Pashmaks Tavas is a cheerleader in the new sports competition named "Pashmaks". This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S 

Codeforces Round #299 (Div. 2)D. Tavas and Malekas

KMP,先预处理按每个节点标记,扫一遍更新每个匹配位置,最后kmp判断是否有重合而且不相同的地方 注意处理细节,很容易runtime error #include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #inclu

#299 (div.2) A. Tavas and Nafas

1.题目描述:点击打开链接 2.解题思路:本题是一道简单的模拟题,要求将小于100的每个数的英文单词输出,提前打表即可.注意0,11~19要特殊处理. 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #include<vector>

Codeforces Round #299 (Div. 2) A. Tavas and Nafas

题目链接:http://codeforces.com/problemset/problem/535/A #include <iostream> #include <string> using namespace std; int main() { string s1[10]={"zero","one","two","three","four","five",&qu

Codeforces B - Tavas and SaDDas

535B - Tavas and SaDDas 方法一:打表大法. 代码1: #include<bits/stdc++.h> using namespace std; int a[1024]={0,4,7,44,47,74,77,444, 447,474,477,744,747,774,777, 4444,4447,4474,4477,4744,4747,4774, 4777,7444,7447,7474,7477,7744,7747, 7774,7777,44444,44447,44474,

Codeforces Round #299 (Div. 2) Tavas and Karafs(二分)

英语渣渣感觉无力...翻了下题解才知道题意... 给你一个无限长的等差数列a,n个查询.对于每个查询,给出l,t,m,求最大的r.表示在等差数列a的第l号元素到第r号元素,执行t次操作,对于每一次操作,在[l,r]区间内选出m个数,并且把这m个数-1,执行完t次操作后,使得区间[l,r]内的数全部为0,求区间最大的右端点r. 如果t小于a[l],那么执行完t次操作a[l]也不会为0,输出-1 那么同理我们可以求出r的范围,r肯定小于等于(t-a)/b,因为数列是递增的. 既然我们都已经知道了范围