暑假训练DAY6 csu七月月赛(水题部分)

A - 商

 CSU - 2143 

编一个程序求A/B的值 ,要求精确到小数点后N位(N<=80的自然数,并且A<B,A和B是整型 数范围),不足N位的用“0”补齐。例如:精确到小数点后9位:6/7=0.857142857。输入A、B、N, 求A/B。

Input

输入文件: 只有一行,就是A,B,N,

Output

输出文件: 只有一行,就是A/B的结果。

Sample Input

6 7 9

Sample Output

0.857142857

简单题不断递归,算出指定的位数即可,注意,不用四舍五入

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>

using namespace std;
int arr[85];
int x,n;
void dfs(int depth,int num)
{
	if(depth==n)
	{
		return;
	}
	arr[depth]=num*10/x;
	dfs(depth+1,num*10%x);
} 
int main()
{
	int y;
	while(cin>>y>>x>>n)
	{
		dfs(0,y);
		printf("0.");
		for(int i=0;i<n;i++)
		{
			printf("%d",arr[i]);
		}
		cout<<endl;
	}
	return 0;
}

B - 平衡等式

 CSU - 2144 

写一个程序要求当输入在整数范围内的一个整数R后, 计算机便会检查,在下式□处能否填上“+”、“-”或“×”号凑成相应等式。如能凑成,则印出所有这些等式的个数。注意,考虑符号的优先级。 1□2□3□4□5□6□7□8□9=R

Input

只有一行,就是一个整数R。

Output

只有一行,就是使等式成立的个数。

Sample Input

20

Sample Output

30

dfs穷举即可

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>

using namespace std;
const double eps=1e-6;
long long cnt=0,R;
int arr[9]={1,2,3,4,5,6,7,8,9};
void dfs(int depth,int num,int befo,int sign)
{
	if(depth==9)
	{
		if(R==num)
		cnt++;
		return;
	}
	
	dfs(depth+1,num+arr[depth],arr[depth],1);
	dfs(depth+1,num-arr[depth],arr[depth],-1);
	dfs(depth+1,num+sign*arr[depth]*befo-sign*befo,arr[depth]*befo,sign);
//	dfs(depth+1,num/arr[depth]);
}
int main()
{
	while(cin>>R)
	{
		cnt=0;
		dfs(1,1,1,1);
		cout<<cnt<<endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值