poj 2551 Ones
本题的想法很简单,就是模拟手算乘法。不一样的是,需要控制输出的结果:每一位都是由1构成的整数。
代码如下:
#include <iostream>
using namespace std; int a[][] ={{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,}}; int get(int n)
{
int k = ,mm,t;
if(n% == ) t = ;
if(n% == ) t = ;
if(n% == ) t = ;
if(n% == ) t = ; int nm = n*a[nm%][t]; while(nm!=)
{
mm = nm%;
if(mm == ) { nm = nm/; k ++;}
else nm = nm + n*a[mm][t];
}
return k;
} int main()
{
int n;
while(cin>>n)
cout<<get(n)<<endl;
return ;
}
注意二维数组的构造方式: 使得每一次第20行代码执行之后的所得到的数的末位是1。数组中的第一维是上一次nm对10的余数,第二维与所输入的数的末位对应。
另外注意,数组a是可以改变的,也就是说,如果遇到有其他的要求的时候,数组a可以根据要求来改变。
poj 2551 Ones的更多相关文章
- POJ 2551
#include<iostream> #include<stdio.h> #include<string> using namespace std; //int m ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
随机推荐
- 自动装箱(boxing)和自动拆箱(unboxing)
摘自:http://www.codeceo.com/article/java-boxing-unboxing.html Java的四类八种基本数据类型 基本类型 占用空间(Byte) 表示范围 包装器 ...
- WCF服务部署IIS
一.将WCF服务部署到IIS上 [转载自简单笑容——http://www.cnblogs.com/skdsxx/p/5072726.html ] 1.首先检测电脑上是否安装了IIS,一般来说Win7 ...
- ubuntu Server 14 自动更新
https://help.ubuntu.com/stable/serverguide/automatic-updates.html http://spin.atomicobject.com/2014/ ...
- [IIS]IIS扫盲(二)
iis - IIS之Web服务器建立 第一篇 IIS之Web服务器 一.建立第一个Web站点 比如本机的IP地址为192.168.0.1,自己的网页放在D:\Wy目录下,网页的首页文件名为Inde ...
- Sql的一些概念
聚合函数 聚合函数可以返回整个或者几个列或者一个列的汇总数据,它常用来计算SELECT语句查询的统计值.聚合函数经常与SELECT语句的GROUP BY 子句一同使用.
- Zepto源码
// Zepto.js // (c) 2010-2016 Thomas Fuchs // Zepto.js may be freely distributed under the MIT licens ...
- CSS 块状元素和内联元素的详解
我们先来分析一下块级元素.内联级元素的定义和解析: 块元素(block element)一般是其他元素的容器元素,块元素一般都从新行开始,它可以容纳内联元素和其他块元素,常见块元素是段落标签'P&q ...
- C++学习基础八——重载输入和输出操作符
一.重载输入操作符的要点: 1.返回值为istream &. 2.第一个参数为istream &in. 3.第二个参数为自定义类型的引用对象(例如Sales_Item &ite ...
- linux网络完全与防护
7.1 网络封包联机进入主机的流程 7.1.1 封包进入主机的流程 1.经过防火墙的分析 iptables 主要功能是封包过滤 主要分析TCP/IP的封包表头来进行过滤的机制 分析的是OSI的第二 ...
- C#之Winform中treeview控件绑定数据库
private DataSet ds; private SqlDataAdapter sqlDataAdapter1; private int maxnodeid; private void Form ...