洛谷循环结构后半部分P1423 小玉在游泳P1720 月落乌啼算钱 P5724 求极差 P1420 最长连号 P1075 质因数分解 P5725 求三角形 P4956 Davor P1089津津的储蓄

P1423 小玉在游泳
简单的数学处理

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double x;
	double v = 2.;
	int cnt=0;
	double xx;
	cin >> x; 
	while(xx<x)
	{
		xx += v;
		v = v*0.98; 
		cnt++;
	}
	cout << cnt;
	return 0;
}

P1720 月落乌啼算钱(斐波那契数列)
把这个数学表达式写出来

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	double a = sqrt(5);
	printf("%.2f",(pow((1+a)/2,n)-pow((1-a)/2,n))/a);
	return 0;
}

P5724 求极差 / 最大跨度值
找最大值和最小值

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int maxx=0,minn=1000;
	while(n--)
	{
		int a;
		cin >> a;
		maxx = max(maxx,a);
		minn = min(minn,a);
	}
	cout << maxx - minn;
	return 0;
}

P1420 最长连号
计数

#include<bits/stdc++.h>
using namespace std;
int a[10001];
int main()
{
	int n;
	cin >> n;
	int ans=1;
	int cnt=1;
	for(int i=0;i<n;i++)
	cin >> a[i];
	for(int i=1;i<n;i++)
	{
		if(a[i]-a[i-1]==1)
		cnt++;
		else
		cnt=1;
		ans=max(ans, cnt);
	}
	cout << ans;
	return 0;
}

P1075 质因数分解
一点小的数学处理,不然TLE

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	for(int i=2;i<n;i++)
	{
		if(n%i==0)
		{
			cout << n/i;
			break;
		}
	}
	return 0;
}

P5725 求三角形
输出图形

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int k=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			printf("%02d",k++);
		}
		cout << endl;
	}
	k=1;
	cout << endl;
	for(int i=0;i<n;i++)
	{
		for(int j=n;j>i+1;j--)
		{
			printf("  ");
		}
		for(int l=0;l<i+1;l++)
		{
			printf("%02d",k++); 
		}
		cout << endl;
	}
	return 0;
}

P4956 Davor
小小的数学变换

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	n /= 364;
	if(n<=103)
	cout << n-3 << endl << 1;
	else
	{
		if(n%3==0) printf("%d\n%d\n",99,(n-99)/3);
		if(n%3==1) printf("%d\n%d\n",100,(n-100)/3);
		if(n%3==2) printf("%d\n%d\n",98,(n-98)/3);
	}
	return 0;
}

P1089 津津的储蓄计划
模拟的实际问题

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum=0;
	int old=0;
	for(int i=0;i<12;i++)
	{
		if(old<0)
		{
			cout << "-" << i;
			return 0;
		}
		int m;
		cin >> m;
		m = 300-m+old;
		sum += (m/100)*100;
		old = m%100; 
	}
	cout << old+sum*1.2;
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三元湖有大锦鲤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值