DGFLSzfd @ 2024-10-13 14:20:05
感觉自己要进场。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
long long n, k,ans=0;
cin>>n>>k;
if (k==0)
{
cout<<1<<endl;
continue;
}
for(long long q=n/(k+1);q*k<=n;q++)
{
long long r=n-(q*k);
if(r<0) break;
if (r<q)
{
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int f(const string &S, int &pos, int x)
{
int result=0;
while (pos<S.length() and isdigit(S[pos]))
{
result=result*10+(S[pos]-'0');
pos++;
}
if (pos == S.length() || S[pos] != 'x')
{
return result;
}//算尽了
//嵌套了下一个三目
bool greater=(S[pos + 1] == '>');
pos += 2;
int con = 0;
while (isdigit(S[pos]))
{
con=con*10+(S[pos]-'0');
pos++;
}
pos++;
int truee = f(S, pos, x);
pos++;
int falsee = f(S, pos, x);
if ((greater and x > con) or (!greater and x < con))
{
return truee;
}
else
{
return falsee;
}
}
int main()
{
int m,q;
cin >>m>>q;
string S;
cin>>S;
while(q--)
{
int x;
cin>>x;
int pos=0;
cout<<f(S,pos,x)<<endl;
}
return 0;
}
by DGFLSzfd @ 2024-10-13 14:43:04
@dear_deer_land T1也快读啊?!看错了,已关
by DDD_et @ 2024-10-13 14:43:21
@DGFLSzfd
其实这题的正确代码没有那么长,只有这么一点……
#include <bits/stdc++.h>
#define int long long
using namespace std;
int t;
signed main ()
{
cin >> t;
while (t --)
{
int n, k; cin >> n >> k;
if (k == 0) { cout << "1\n"; continue; }
cout << (n / k) - (n / (k + 1)) << '\n';
}
return 0;
}
找规律只有这么点啊……
求关
by DGFLSzfd @ 2024-10-13 14:44:20
@0Io_oI0 解释一下啊大佬
by DDD_et @ 2024-10-13 14:48:52
@DGFLSzfd
原理如下:
首先用脑子想想只要是
比如 n = 100
,k = 2
,那么 n / (100/2~100/3)
的结果都为 100/2 - 100/3 = 17
,如果 100/3-100/4=8
,所以规律就是 n/k-n/(k-1)
,但是要特判
by DDD_et @ 2024-10-13 14:49:24
我个人觉得我的规律简洁一些……
by DDD_et @ 2024-10-13 14:50:31
啊不对,是 100/3-100/4
,上面写错了
by DGFLSzfd @ 2024-10-13 14:51:59
@DDD_et 谢谢,不过楼上已有正解,一句话:
by DDD_et @ 2024-10-13 14:54:30
@DGFLSzfd
一点没错
by DGFLSzfd @ 2024-10-13 14:57:32
@DDD_et 讲一下第三题呗dalao
by DDD_et @ 2024-10-13 15:06:05
@DGFLSzfd
我不是dalao(哭)
我第三题没做出来(哇哇大哭)