洛谷P3048 [USACO12FEB]牛的IDCow IDs
2017-09-22 18:12
399 查看
P3048 [USACO12FEB]牛的IDCow IDs
题目描述
Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitious, and only labels cows with binary numbers that have exactly K "1" bits (1 <= K <= 10). The leading bit of each label is always a "1" bit, of course. FJ assigns labels in increasing numeric order, starting from the smallest possible valid label -- a K-bit number consisting of all "1" bits. Unfortunately, he loses track of his labeling and needs your help: please determine the Nth label he should assign (1 <= N <= 10^7).FJ给他的奶牛用二进制进行编号,每个编号恰好包含K 个"1" (1 <= K <= 10),且必须是1开头。FJ按升序编号,第一个编号是由K个"1"组成。
请问第N(1 <= N <= 10^7)个编号是什么。
输入输出格式
输入格式:Line 1: Two space-separated integers, N and K.
输出格式:
输入输出样例
输入样例#1:7 3
输出样例#1:
10110
#include<cstdio> using namespace std; int n,k,j; int a[13]; int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=k;i++)a[i]=i; for(int i=2;i<=n;i++){ j=1; while(1){ a[j]++; if(a[j]!=a[j+1])break; a[j]=j; j++; } } j=k; for(int i=a[k];i>=1;i--){ if(a[j]==i)printf("1"),j--; else printf("0"); } return 0; }
100分 模拟?
相关文章推荐
- 洛谷P3048 [USACO12FEB]牛的IDCow IDs
- 洛谷 P3048 [USACO12FEB]牛的IDCow IDs
- 洛谷 P3047 [USACO12FEB]附近的牛Nearby Cows
- 树形dp-洛谷 P3047 [USACO12FEB]附近的牛Nearby Cows
- |洛谷|堆|P3045 [USACO12FEB]牛券Cow Coupons
- 洛谷 P3047 [USACO12FEB]附近的牛Nearby Cows
- [洛谷3047]USACO12FEB附近的牛
- [USACO12FEB]Nearby Cows solution 题解 [洛谷3047]
- 【洛谷3047】[USACO12FEB]附近的牛Nearby Cows
- 树形DP【洛谷P3047】 [USACO12FEB]附近的牛Nearby Cows
- 【洛谷3047】[USACO12FEB]附近的牛Nearby Cows
- 【USACO14FEB】洛谷3102 Secret Code
- 【USACO13DEC】洛谷3094 Vacation Planning
- |洛谷|模拟|P1203 [USACO1.1]坏掉的项链Broken Necklace
- 【枚举】洛谷 P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib
- 洛谷P3097 [USACO13DEC]最优挤奶Optimal Milking【线段树】
- 【洛谷 1339】【USACO 09 OCT】热浪 Heat Wave
- 洛谷 P2742 [USACO5.1]圈奶牛Fencing the Cows
- 线段树+扫描线【p1884】[Usaco12FEB]过度种植(银)Overplanting …
- 洛谷p1709 [USACO5.5]隐藏口令Hidden Password