Codeforces Round #710 Div. 3
A. Strange Table
代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int T;
int a[N];
#define int long long
// typedef long long ll;
signed main()
{
ios::sync_with_stdio(false),cin.tie(0);
cin>>T;
while(T--)
{
int n,m,x;
cin>>n>>m>>x;
int a=(x+n-1)/n,b=x%n;
if(b==0)b=n;
cout<<(b-1)*m+a<<endl;
}
return 0;
}
B. Partial Replacement
思路:
从第一个星号开始,在后面的K距离中,找到最后一个星号;直接跳到那里;如果后面没有星号则说明到达末尾.
代码
#include<bits/stdc++.h>
using namespace std;
int T,n,k;
string s;
void solve()
{
cin>>n>>k>>s;
int l=0;
while(s[l]!='*')l++;
int ans=0;
while(l<n)
{
ans++;
int nl=n;
for(int i=1;i<=k;i++)
{
if(l+i<n&&s[l+i]=='*')nl=l+i;
}
l=nl;
}
cout<<ans<<endl;
}
int main()
{
cin>>T;
while(T--)
{
solve();
}
}