题目背景:
原来的题目太简单,现改进让小鱼周末也休息,请已经做过重做该题。
题目描述:
有一只小鱼,它平日每天游泳 250 公里,周末休息(实行双休日),假设从周 x(1≤x≤7)x(1\le x \le 7)x(1≤x≤7) 开始算起,过了 n(n≤106)n(n\le 10^6)n(n≤106) 天以后,小鱼一共累计游泳了多少公里呢?
输入格式:
输入两个整数x,n(表示从周x算起,经过n天)。
输出格式:
输出一个整数,表示小鱼累计游泳了多少公里。
先是大佬代码:
#include<bits/stdc++.h> //包含了所有C++头文件的头文件
using namespace std;
int main()
{
unsigned long long n,ans=0; //坑就坑在这儿。天数都那么大了,总路程还会小吗???
int x;
cin >> x >> n; //输入星期和持续天数
for(int i=0;i<n;i++)
{
if((x!=6)&&(x!=7)) //只要星期不等于6和7
ans += 250; //总长度增加250
if(x==7) //当x等于7的时候
x=1; // x归位为1
else //其他情况下(x不等于7的时候)
x++; //x自加1
}
cout << ans; //输出总路程
return 0;
}
link.
作者: Hoshizawa.(洛谷)
这道题不难,就是如上述的一个坑,数的大小。。。int错了n遍。
当然不只,还有别的错。。。不清楚如何去判定x,将星期带入了循环,差点没出来。。。。。哭唧唧
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#define PI 3.1415926535
#include<functional>
#include<vector>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=3e4+10;
const ll _INF = -8e18;
const int N = 1e5 + 10;
bool cmp(ll a,ll b)
{
return a>b;
}//从大到小
int main()
{
ll i;
ll x,n,k,sum=0;
cin>>x>>n;
for(i=1; i<=n; i++)
{
if((x!=6)&&(x!=7))
sum+=250;
if(x==7)
x=1;
else
x+=1;
}
printf("%lld",sum);
return 0;
}
一直在道路上坚持爬行的菜
另附一个简介代码,
#include<iostream>
using namespace std;
int main()
{
int x, n;
cin >> x >> n;
cout << (n - (int(n / 7.0+0.5) * 2 + ((n % 7 != 0) ? ((x - 6 >= 0) ? 1 : 0) : 0))) * 250 << endl;
return 0;
}
作者: Cawell_Anki
nice~~