孪生漂亮数

This commit is contained in:
James 2020-04-05 08:23:13 +08:00
parent 670b2a624d
commit e12a6fc759
9 changed files with 62 additions and 83 deletions

View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1,44 @@
#include <iostream>
using namespace std;
bool f[1001] = { 0 };
bool pan(int n)
{
if (n == 2) {
return 1;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
bool dg(int n)
{
for (int i = 2; i * i <= n; i++) {
if (pan(i) == 1) {
int now = i;
for (int j = 1; now <= n; j++) {
now *= i;
if (now == n) {
return 1;
}
if (n%now==0&&dg(n / now) == 1) {
//cout<<now<<" "<<n-now<<endl;
return 1;
}
}
}
}
return 0;
}
int main()
{
for (int i = 10;; i++) {
f[i] = dg(i);
if (f[i] == 1 && f[i - 1] == 1) {
cout << i - 1 << " " << i;
return 0;
}
}
}

Binary file not shown.

View File

@ -0,0 +1,6 @@
#include <iostream>
int main()
{
std::cout << "Hello Easy C++ project!" << std::endl;
}

BIN
1655_goodlooknum/main.exe Normal file

Binary file not shown.

View File

View File

@ -0,0 +1,6 @@
## z:\Chao\src\1655_goodlooknum\test\in.txt
2020/04/04 ÖÜÁù 23:25:42.97
288 289
-----------------------------------------------
Process exited after 140 ms with return value 0

View File

@ -1,83 +0,0 @@
#include <iostream>
using namespace std;
int n, now = 0, m, e[100001][2] = { 0 }, g[100001] = { 0 }, p[100001][4] = { 0 };
int mins(int a, int b)
{
return a < b ? a : b;
}
int maxs(int a, int b)
{
return a > b ? a : b;
}
void party(int a, int b)
{
//cout << a << " " << b << ":";
if (g[a] == 0 && g[b] == 0) {
g[a] = ++now;
g[b] = now;
int a0 = e[a][0], b0 = e[b][0], a1 = e[a][1], b1 = e[b][1];
p[now][0] = mins(a0, b0);
p[now][1] = mins(a1, b1);
p[now][2] = maxs(a0, b0);
p[now][3] = maxs(a1, b1);
} else {
while (p[g[a]][0] == -1) {
a = p[g[a]][3];
}
while (p[g[b]][0] == -1) {
b = p[g[b]][3];
}
if (g[a] > g[b]) {
int o = a;
a = b;
b = o;
}
//cout << g[a] << "?";
//cout << g[b] << "?" << endl;
if (g[a] == 0) {
g[a] = g[b];
int a0 = e[a][0], a1 = e[a][1];
p[g[b]][0] = mins(a0, p[g[b]][0]);
p[g[b]][1] = mins(a1, p[g[b]][1]);
p[g[b]][2] = maxs(a0, p[g[b]][2]);
p[g[b]][3] = maxs(a1, p[g[b]][3]);
} else {
if (g[a] != g[b]) {
p[g[b]][0] = mins(p[g[a]][0], p[g[b]][0]);
p[g[b]][1] = mins(p[g[a]][1], p[g[b]][1]);
p[g[b]][2] = maxs(p[g[b]][2], p[g[b]][2]);
p[g[b]][3] = maxs(p[g[b]][3], p[g[b]][3]);
p[g[a]][0] = -1, p[g[a]][3] = b;
}
}
}/*
for (int i = 0; i <= 3; i++) {
cout << p[g[a]][i] << " ";
}
cout << endl;
for (int i = 0; i <= 3; i++) {
cout << p[g[b]][i] << " ";
}
cout << endl;*/
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> e[i][0] >> e[i][1];
}
for (int i = 1; i <= m; i++) {
int yi, er;
cin >> yi >> er;
//cout << i << "||";
party(yi, er);
}
int ans = 400000000;
for (int i = 1; i <= now; i++) {
if (p[i][0] != -1) {
int zhou = p[i][2] - p[i][0] + p[i][3] - p[i][1];
ans = mins(zhou * 2, ans);
}
}
cout << ans;
}