<NOIP> 27 . P1618 三连击(升级版)
2017-07-04 23:28
429 查看
题解:这道题是洛谷的第27道题目,我是感觉不需要递归全排列,依旧是暴力即可。
源代码:
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
#include <iostream>
#include <stdlib.h>
using namespace std;
bool check(int *first, int *second)
{
if (first[0] != second[0] && first[0] != second[1] && first[0] != second[2] &&
first[1] != second[0] && first[1] != second[1] && first[1] != second[2] &&
first[2] != second[0] && first[2] != second[1] && first[2] != second[2] &&
first[0] != first[1] && first[0] != first[2] && first[1] != first[2] &&
second[0] != second[1] && second[0] != second[2] && second[1] != second[2] &&
first[1] != 0 && first[2] != 0 && second[1] != 0 && second[2] != 0)
return true;
else
return false;
}
int main()
{
bool is = false;
int a1, a2, a3;
cin >> a1 >> a2 >> a3;
for (size_t i = 100; i < 1000; i++)
{
int a = i;
int b = (a2*a / a1);
int c = (a3*a / a1);
int d = a;
int e = b;
int f = c;
if (b < 1000 && c < 1000)
{
// 提取位数;
int aArray[3],
bArray[3],
cArray[3];
for (size_t i = 0; i < 3; i++)
{
aArray[i] = a % 10; a /= 10;
bArray[i] = b % 10; b /= 10;
cArray[i] = c % 10; c /= 10;
}
if (check(aArray, bArray) && check(aArray, cArray) && check(bArray, cArray))
{
cout << d << " " << e << " " << f << endl;
is = true;
}
}
}
if (!is) cout << "No!!!" << endl;
system("pause");
return 0;
}
源代码:
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
#include <iostream>
#include <stdlib.h>
using namespace std;
bool check(int *first, int *second)
{
if (first[0] != second[0] && first[0] != second[1] && first[0] != second[2] &&
first[1] != second[0] && first[1] != second[1] && first[1] != second[2] &&
first[2] != second[0] && first[2] != second[1] && first[2] != second[2] &&
first[0] != first[1] && first[0] != first[2] && first[1] != first[2] &&
second[0] != second[1] && second[0] != second[2] && second[1] != second[2] &&
first[1] != 0 && first[2] != 0 && second[1] != 0 && second[2] != 0)
return true;
else
return false;
}
int main()
{
bool is = false;
int a1, a2, a3;
cin >> a1 >> a2 >> a3;
for (size_t i = 100; i < 1000; i++)
{
int a = i;
int b = (a2*a / a1);
int c = (a3*a / a1);
int d = a;
int e = b;
int f = c;
if (b < 1000 && c < 1000)
{
// 提取位数;
int aArray[3],
bArray[3],
cArray[3];
for (size_t i = 0; i < 3; i++)
{
aArray[i] = a % 10; a /= 10;
bArray[i] = b % 10; b /= 10;
cArray[i] = c % 10; c /= 10;
}
if (check(aArray, bArray) && check(aArray, cArray) && check(bArray, cArray))
{
cout << d << " " << e << " " << f << endl;
is = true;
}
}
}
if (!is) cout << "No!!!" << endl;
system("pause");
return 0;
}
相关文章推荐
- <NOIP> 7 . P1008 三连击
- <noip>陶陶摘苹果
- <Win32_11>程序员求爱的创意程序——升级版^_^
- <NOIP> 19 . P1553 数字反转(升级版)
- <LeetCode><Easy> 27 Remove Elements
- 洛谷P1618 三连击(升级版)
- <NOIP> 10 . P1423 小玉在游泳
- <NOIP> 21 . P1914 小书童——密码
- <NOIP> 23 . P1036 选数
- <NOIP> 12 . P1980 计数问题
- <NOIP> 24 . P1149 火柴棒等式
- <二分||线段树>【noip 2012】codevs 1217 借教室
- <NOIP> 25 . P1217 [USACO1.5]回文质数 Prime Palindromes
- [洛谷1618]三连击(升级版)
- <NOIP> 13 . P1046 陶陶摘苹果
- <NOIP> 14 . P1047 校门外的树
- <NOIP> 5 . P1085 不高兴的津津
- <棋盘型DP> noip 2008 传纸条
- luogu【1618】三连击(升级版)
- <NOIP> 4 . P1425 小鱼的游泳时间