题解分享
题解分享简介
奇怪的分式(结果填空) - 题解
```
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int res=0;
for(int x1=1;x1<=9;x1++)
for(int x2=1;x2<=9;x2++)
for(int y1=1;y1<=9;y1++)
for(int y2=1;y2<=9;y2++)
{
if(x1==x2&&y1==y2) continue;
double a=(x2*y2*1.0)/(x1*y1);
double b=(x2*10+y2*1.0)/(x1*10+y1);
if(a==b) res++;
}
cout<<res;
return 0;
}
```
查看全文
0
0
0
3
奇怪的分式(结果填空) - 题解
直接暴力破解
```
public class Main {
public static void main(String[] args) {
// 原等式为 (a/c) * (b/d) = ( a*10 + c/ b*10 + d )
// 但是直接使用除法的话有错误的可能性
// 可表示为 (a*b)*(c*10+d) = (a*10+b)*(c*d)
int count = 0;
for (int a = 1; a <= 9; a++) {
for (int b = 1; b <= 9; b++) {
for (int c = 1; c <= 9; c++) {
// 分子分母相同 于是跳过
if (c == a)
continue;
for (int d = 1; d <= 9; d++) {
// 分子分母相同 于是跳过
if (d == b)
continue;
if ((a * b) * (c * 10 + d) == (a * 10 + b) * (c * d))
count++;
}
}
}
}
System.out.println(count);
}
}
```
查看全文
0
0
0
3
奇怪的分式(结果填空) - 题解
暴力😄
```c++
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int res = 0;
for (double a1 = 1; a1 <= 9; ++a1) {
for (double a2 = 1; a2 <= 9; ++a2) {
for (double b1 = 1; b1 <= 9; ++b1) {
for (double b2 = 1; b2 <= 9; ++b2) {
if (a1 == a2 || b1 == b2)
continue;
if ((double)a1/a2 * b1/b2 == (double)((a1 * 10) + b1)/((a2 * 10) + b2))
++res;
}
}
}
}
printf("%d\n", res);
return 0;
}
```
查看全文
0
0
0
0
奇怪的分式(结果填空) - 题解
```cpp
bool st[15];
double num[15];
int cnt = 0;
void dfs(int x)
{
if (x > 4)
{
if (num[1] != num[2] and num[3] != num[4])
{
if (num[1] * num[3] * (num[2] * 10 + num[4]) == num[2] * num[4] * (num[1] * 10 + num[3]))
cnt++;
}
return;
}
for (int i = 1; i <= 9; i++)
{
num[x] = i;
dfs(x + 1);
}
}
void solve()
{
dfs(1);
cout << cnt << endl;
}
```
查看全文
0
0
0
0
奇怪的分式(结果填空) - 题解
```
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 4
int cnt;
int path[N];
bool vis[N];
bool check(int a,int b,int c,int d)
{
if(a==b&&c==d)return false;
if(a*c*(10*b+d)==b*d*(10*a+c))return true;
return false;
}
void dfs(int u)
{
if(u==4)
{
if(check(path[0],path[1],path[2],path[3]))
{
cnt++;
for(int i=0;i<4;i++)cout<<path[i]<<" ";
puts("");
}
return ;
}
for(int i=1;i<=9;i++)
{
path[u]=i;
dfs(u+1);
}
}
int main()
{
dfs(0);
cout<<cnt<<endl;
return 0;
}
```
查看全文
0
0
0
0



