C++-POJ1016-Numbers That Count
无语,15步产生16个数,植树原理啊!
大水题,居然wa了好几次,唉,自己的问题。
略略略,就要封装成结构体,略略略。
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct String {
char s[];
int len_s,len_b;
int a[],b[];
void init() {
memset(s,,sizeof(s));
memset(a,,sizeof(a));
memset(b,,sizeof(b));
len_s=len_b=;
}
bool read() {
scanf("%s",s+);
len_s=strlen(s+);
if(s[]=='-')return false;
return true;
}
void calc() {
for(int i=; i<=len_s; i++)a[s[i]-'']++;
for(int i=; i<=; i++)
if(a[i]) {
if(a[i]<){
b[++len_b]=a[i];
b[++len_b]=i;
}
else {
b[++len_b]=a[i]/;
b[++len_b]=a[i]%;
b[++len_b]=i;
}
}
}
void get(String A) {
len_s=A.len_b;
for(int i=; i<=len_s; i++)
s[i]=A.b[i]+'';
}
void print_s() {for(int i=; i<=len_s; i++)cout<<s[i];}
};
bool comp(String A,String B) {
if(A.len_s!=B.len_s)return false;
for(int i=; i<=A.len_b; i++)if(A.s[i]!=B.s[i])return false;
return true;
}
bool self(String A) {
if(A.len_s!=A.len_b)return false;
for(int i=; i<=A.len_s; i++)if(A.s[i]-''!=A.b[i])return false;
return true;
}
String a[],A;
int main() {
while(A.read()) {
A.calc(),a[]=A;
for(int i=; i<=; i++) a[i].get(a[i-]),a[i].calc();
int ans,flag=;
for(int i=; i<=; i++) {
if(flag)break;
if(self(a[i]))
{flag=;ans=i-;break;}
for(int j=i+; j<=; j++)
if(comp(a[i],a[j]))
{ans=j-i;flag=;break;}
}
A.print_s();
if(flag==)
if(ans==)cout<<" is self-inventorying"<<endl;
else cout<<" is self-inventorying after "<<ans<<" steps"<<endl;
else if(flag==)cout<<" enters an inventory loop of length "<<ans<<endl;
else cout<<" can not be classified after 15 iterations"<<endl;
A.init();for(int i=;i<=;i++)a[i].init();
}
return ;
}
C++-POJ1016-Numbers That Count的更多相关文章
- POJ1016 Numbers That Count
题目来源:http://poj.org/problem?id=1016 题目大意: 对一个非负整数定义一种运算(inventory):数这个数中各个数字出现的次数,然后按顺序记录下来.比如“55531 ...
- poj 1016 Numbers That Count
点击打开链接 Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17922 Accep ...
- B - Numbers That Count
Description "Kronecker's Knumbers" is a little company that manufactures plastic di ...
- Numbers That Count POJ - 1016
"Kronecker's Knumbers" is a little company that manufactures plastic digits for use in sig ...
- POJ 1016 Numbers That Count 不难,但要注意细节
题意是将一串数字转换成另一种形式.比如5553141转换成2个1,1个3,1个4,3个5,即21131435.1000000000000转换成12011.数字的个数是可能超过9个的.n个m,m是从小到 ...
- Random Numbers Gym - 101466K dfs序+线段树
Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...
- 2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest K - Random Numbers (dfs序 线段树+数论)
Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...
- Java中有关Null的9件事
对于Java程序员来说,null是令人头痛的东西.时常会受到空指针异常 (NPE)的骚扰.连Java的发明者都承认这是他的一项巨大失误.Java为什么要保留null呢?null出现有一段时间了,并且我 ...
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
- LeetCode "477. Total Hamming Distance"
Fun one.. the punch line of this problem is quite common in Bit related problems on HackerRank - vis ...
随机推荐
- 安装MySQL被提示缺少msvcr120.dll,msvcp120.dll或提示0xc00007b错误
踩坑经历: 我的电脑昨天重装了win10系统,在安装MySQL时被提示缺少msvcr120.dll,我去下载msvcr120.dll后放入System32中,又被提示缺少msvcp120.dll,然后 ...
- Codeforces Round #624 (Div. 3)
A.题意:通过加奇数减偶数的操作从a到b最少需要几步 签到题 #include <algorithm> #include <iostream> #include <cst ...
- 安装jupyter使用notebook
安装jupyter pip3 install jupyter --default-timeout=1000 -i https://pypi.tuna.tsinghua.edu.cn/simple 使用 ...
- CSS之 元素显示隐藏,用户界面样式,文本溢出隐藏,精灵技术,三角形
元素的显示与隐藏 display 显示 display 设置或检索对象是否及如何显示 display: none; 隐藏对象 display: block; 除了转换为块级元素, 同时还有显示元素的意 ...
- ubuntu安装配置heirloom-mailx使用外部smtp发送外网email
1- 安装 1.1- 添加heirloom-mailx apt源 cat /etc/apt/sources.list.d/mailx.list deb http://cz.archive.ubuntu ...
- 强烈推荐一款强大的公式编辑器软件AxMath
Axmath教程请移步:https://www.cnblogs.com/coco56/p/11759578.html
- numpy学习(一)
(一)基础学习 学习渠道:阿里天池AI学习——Numpy基础(传送门) (二)练习篇 练习渠道:Numpy基础100题(Part 1) 1. Import the numpy package unde ...
- Web基础-Uri跟Url的区别
关于URL和URI的区别,个人见解. 初学java,最近被一个概念搞得头晕脑胀,就是url和uri的概念和区别,网上查了一大通,发现各种回答眼花缭乱,有百科直接粘贴的,有胡说八道的,有故意绕来绕 ...
- arm学习笔记
学习ARM也有一定时间了,想想还是记点东西,要不以后就忘了.这是我的第一片,简简单单.但比较基础.1. ARM中一些常见英文缩写解释MSB:最高有效位:LSB:最低有效位:AHB:先进的高性能总线:V ...
- 2020牛客寒假算法基础集训营2 J.求函数 (线段树 推公式 单点修改 区间查询)
https://ac.nowcoder.com/acm/contest/3003/J 题解: #include<bits/stdc++.h> typedef long long ll; u ...