pat 1005 继续(3n+1)猜想
来源:互联网 发布:淘宝格子湖铺 编辑:程序博客网 时间:2024/06/05 05:16
//解题思想:对数列中的每个数进行验证, 如果此数覆盖了其他数,则将其他数置为可覆盖
//依次类推
#include<iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
vector<int> vec;
void Panduan(int n)
{
while (n != 1)
{
if (n % 2 == 0)
{
n /= 2;
vec.push_back(n);
}
else
{
n = (n * 3 +1)/2;
vec.push_back(n);
}
}
}
int main()
{
int n;
cin>>n;
int *temp = new int[n];
bool *flage = new bool[n];
vector<int> truevec;
for (int i = 0; i < n; i++)
{
temp[i] = 0;
flage[i] = false;//0为不能背覆盖,1为能被覆盖
cin >> temp[i];
}
for (int i = 0; i < n; i++)
{
Panduan(temp[i]);
//开始查找被覆盖的数
for (int i = 0; i < vec.size(); i++)
{
for (int j = 0; j < n; j++)
{
if (vec[i] == temp[j])
{
flage[j] = true;//若能找到,则置为能覆盖
}
}
}
}
for (int i = 0; i < n; i++)
{
if (flage[i] == false)
{
truevec.push_back(temp[i]);
//cout<<temp[i]<<" ";
}
}
sort(truevec.begin(), truevec.end());
for (int i = truevec.size()-1; i > 0; i--)
{
cout<<truevec[i]<<" ";
}
cout<<truevec[0]<<endl;
}
//依次类推
#include<iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
vector<int> vec;
void Panduan(int n)
{
while (n != 1)
{
if (n % 2 == 0)
{
n /= 2;
vec.push_back(n);
}
else
{
n = (n * 3 +1)/2;
vec.push_back(n);
}
}
}
int main()
{
int n;
cin>>n;
int *temp = new int[n];
bool *flage = new bool[n];
vector<int> truevec;
for (int i = 0; i < n; i++)
{
temp[i] = 0;
flage[i] = false;//0为不能背覆盖,1为能被覆盖
cin >> temp[i];
}
for (int i = 0; i < n; i++)
{
Panduan(temp[i]);
//开始查找被覆盖的数
for (int i = 0; i < vec.size(); i++)
{
for (int j = 0; j < n; j++)
{
if (vec[i] == temp[j])
{
flage[j] = true;//若能找到,则置为能覆盖
}
}
}
}
for (int i = 0; i < n; i++)
{
if (flage[i] == false)
{
truevec.push_back(temp[i]);
//cout<<temp[i]<<" ";
}
}
sort(truevec.begin(), truevec.end());
for (int i = truevec.size()-1; i > 0; i--)
{
cout<<truevec[i]<<" ";
}
cout<<truevec[0]<<endl;
}
0 0
- pat 1005 继续(3n+1)猜想
- PAT 1005 继续(3n+1)猜想
- PAT 1005 继续(3n+1)猜想
- PAT 1005 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT--继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- pat 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT B1005. 继续(3n+1)猜想
- PAT继续(3n+1)猜想
- PAT basic 1005 : 继续(3n+1)猜想
- 浙江大学PAT---Basic Level---1005----继续(3n+1)猜想
- PAT(BASIC)1005 继续3n+1猜想
- [数据结构_1]saddle_point(马鞍点程序)
- Android Splash界面支持用户点击 直接进入主界面
- 黑马程序员-----银行业务调度系统
- 又是伤感时节~
- UVa 10785 - The Mad Numerologist
- pat 1005 继续(3n+1)猜想
- 自增、自减运算符的运算
- [数据结构_2]Saddle_Point_pro(马鞍点_改进版)
- ZOJ 3228 Searching the String(AC自动机)
- 从文本中统计字符权重并依次构建huffman树
- 算法与数据结构简介
- Lua 安装
- Linux认证考试
- Qt下使用OpenGL(19)-根据NeHe的教程改写的