codeforces round 299 div2 题解
2015-04-28 16:22
337 查看
A. Tavas and Nafas
将0到99的数字变成英文的表示。处理好特殊情况就行了。
B. Tavas and SaDDas
定义仅有数字4和数字7组成的数是幸运数字,给定一个仅有数字4和数字7组成的数,问这个数在所有幸运数字中按升序排列是第几个幸运数。我们写下几个幸运数字,就会发现一位数的有2个,两位数的有4个,三位数的有八个,…,一次类推。我们就可以找到k位数的第一个数是第几位,为了找到特定的数,我们发现,幸运数仅有两种数字组成,和二进制有着异曲同工之妙,我们把4看成二进制的0,7看成二进制的1,我们发现这个二进制表示的十进制就是这个幸运数在k位数中的偏移量。
将0到99的数字变成英文的表示。处理好特殊情况就行了。
#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <cstring> #include <queue> #include <stack> #include <map> #include <set> using namespace std; char str[100]; int main(int argc, char *argv[]) { int n; while (scanf("%d", &n) != EOF) { int x = n / 10; int y = n % 10; if (x == 0) { } else if (x == 1) { switch (n) { case 10: printf("ten\n"); break; case 11: printf("eleven\n"); break; case 12: printf("twelve\n"); break; case 13: printf("thirteen\n"); break; case 14: printf("fourteen\n"); break; case 15: printf("fifteen\n"); break; case 16: printf("sixteen\n"); break; case 17: printf("seventeen\n"); break; case 18: printf("eighteen\n"); break; case 19: printf("nineteen\n"); break; } continue; } else { switch (x) { case 2: printf("twenty"); break; case 3: printf("thirty"); break; case 4: printf("forty"); break; case 5: printf("fifty"); break; case 6: printf("sixty"); break; case 7: printf("seventy"); break; case 8: printf("eighty"); break; case 9: printf("ninety"); break; } if (y != 0) { printf("-"); } } str[0] = '\0'; switch (y) { //case 0: strcpy(str, "zero"); break; case 1: strcpy(str, "one"); break; case 2: strcpy(str, "two"); break; case 3: strcpy(str, "three"); break; case 4: strcpy(str, "four"); break; case 5: strcpy(str, "five"); break; case 6: strcpy(str, "six"); break; case 7: strcpy(str, "seven"); break; case 8: strcpy(str, "eight"); break; case 9: strcpy(str, "nine"); break; } if (n == 0) { printf("zero"); } printf("%s\n", str); } return 0; }
B. Tavas and SaDDas
定义仅有数字4和数字7组成的数是幸运数字,给定一个仅有数字4和数字7组成的数,问这个数在所有幸运数字中按升序排列是第几个幸运数。我们写下几个幸运数字,就会发现一位数的有2个,两位数的有4个,三位数的有八个,…,一次类推。我们就可以找到k位数的第一个数是第几位,为了找到特定的数,我们发现,幸运数仅有两种数字组成,和二进制有着异曲同工之妙,我们把4看成二进制的0,7看成二进制的1,我们发现这个二进制表示的十进制就是这个幸运数在k位数中的偏移量。
/************************************************************************* > File Name: b.cpp > Author: gwq > Mail: gwq5210@qq.com > Created Time: 2015年04月28日 星期二 15时44分38秒 ************************************************************************/ #include <cmath> #include <ctime> #include <cctype> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #include <queue> #include <stack> #include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #define INF (INT_MAX / 10) #define clr(arr, val) memset(arr, val, sizeof(arr)) #define pb push_back #define sz(a) ((int)(a).size()) using namespace std; typedef set<int> si; typedef vector<int> vi; typedef map<int, int> mii; typedef long long ll; const double esp = 1e-5; ll count(ll n) { ll res = 0; while (n) { ++res; n /= 10; } return res; } ll getans(ll n) { ll m = 1; ll ans = 0; while (n) { int x = n % 10; n /= 10; if (x == 7) { ans += m; } //printf("%d %d %d\n", n, ans, m); m *= 2; } return ans; } int main(int argc, char *argv[]) { int n; while (scanf("%d", &n) != EOF) { ll cnt = count(n); ll ans = (1 << cnt) - 1 + getans(n); printf("%lld\n", ans); } return 0; }
相关文章推荐
- Codeforces Round #299 (Div. 1) C. Tavas and Pashmaks
- Codeforces Round #299 (Div. 2) C. Tavas and Karafs 二分搜索+数列
- Codeforces Round #299 Div2 解题报告
- Codeforces Round #299 (Div. 2) D. Tavas and Malekas KMP+预处理、string suffix structures
- Codeforces Round #299 (Div. 2)【A,B,C】
- 【Codeforces Round 299 (Div 2)D】【KMP 本质是最前与最后匹配】Tavas and Malekas 长度为n的匹配串被模板串多位点覆盖的匹配串个数
- Codeforces Round #299 (Div. 1) A. Tavas and Karafs(二分)
- Codeforces Round #299 (Div. 1)C. Tavas and Pashmaks
- Codeforces Round #299 (Div. 2)
- DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
- Codeforces Round #299 (Div. 1) 解题报告 (AB)
- Codeforces Round #299 (Div. 1)C. Tavas and Pashmaks (凸壳)
- Codeforces Round #202 (Div. 1) A. Mafia
- 【瞎搞】 Codeforces Round 276 DIV 2 C.Bits
- Codeforces Round #442 (Div. 2) E. Danil and a Part-time Job DFS序+树链剖分+线段树区间^
- Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 开关--并查集
- Codeforces Round #462 (Div. 2) D. A Determined Cleanup
- Codeforces Round #139 (Div. 2)C Barcode DP
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #296 (Div. 2) —— C(set/multiset)