A. Madoka and Strange Thoughts
手模样例5
当n=5时,
有本身(1,1),(2,2),(3,3),(4,4),(5,5)
有两倍的(1,2),(2,4)
有三倍的(1,3)
其中两倍和三倍的,顺序都可以互换,(1,2),(2,1),(2,4),(4,2),(1,3),(3,1)
因为在1-5里边找一对数(x,y),呈k倍关系,就有n/k对(最大的x只能是n/k向下取整)这样的数。
所以是5+(5/2*2)+(5/3*3)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define x first
#define y second
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
#define rep(a,b,c) for(int a=b;a<c;a++)
#define rep2(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>c;a--)
#define per2(a,b,c) for(int a=b;a>=c;a--)
#define YES {cout<<"YES"<<endl;return;}
#define NO {cout<<"NO"<<endl;return;}
void solve()
{
int n;
cin>>n;
int res=n;
res+=n/2*2;
res+=n/3*2;
cout<<res<<endl;
}
signed main(void)
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--)solve();
}
B. Madoka and Underground Competitions
B有很多种解法,我的解法是去繁从简(懒得思考太多)。
模拟题,先得把模拟的起点找出来,想着如果以(r,c)为起点,就很复杂,那就以(r,c)为基准,寻找一个最靠左上角的坐标作为起点,然后从左往右,从上往下放‘X'
(我估计这里应该也可以按照x-y函数图像的方式去放'X',就是找出斜率相同,间距为某个值的直线,把'X'放在直线中每个对应的整点上。)
我的代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define x first
#define y second
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
#define rep(a,b,c) for(int a=b;a<c;a++)
#define rep2(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>c;a--)
#define per2(a,b,c) for(int a=b;a>=c;a--)
#define YES {cout<<"YES"<<endl;return;}
#define NO {cout<<"NO"<<endl;return;}
char str[510][510];
void solve()
{
int n,k,r,c;
cin>>n>>k>>r>>c;
if(r>c)swap(r,c);
c=(((r-1)+c-1)%n+1)%k;
if(c==0)c=k;
r=1;
//cout<<r<<" "<<c<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
str[i][j]='.';
}
}
for(int i=1;i<=n;i++)
{
int tmp=c;
for(int j=tmp;j<=n;j+=k)
{
str[i][j]='X';
}
for(int j=tmp;j>=1;j-=k)
{
str[i][j]='X';
}
c--;
if(c==0)c=n;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cout<<str[i][j];
}
cout<<endl;
}
}
signed main(void)
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--)solve();
}
C. Madoka and Formal Statement
其实a可以所有值都变成maxa(且每个ai相同)后仍然继续无限增大
1.每个a都不能--,所以当存在ai>bi时,NO
2.到达b的a值无需再考虑,未到达的,我们让ai能到达bi的条件是,bi<=b(i%n+1)+1,因为当a(i%n+1)到达b(i%n+1)时,ai最大只能比后者大一
(因为:Given an array of integer a1,a2,…,an. In one operation you can make ai:=ai+1 if i<n and ai≤ai+1, or i=n and ai≤a1.)
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ll long long
#define double long double
#define x first
#define y second
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
#define rep(a,b,c) for(int a=b;a<c;a++)
#define rep2(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>c;a--)
#define per2(a,b,c) for(int a=b;a>=c;a--)
#define YES {cout<<"YES"<<endl;return;}
#define NO {cout<<"NO"<<endl;return;}
int a[200010],b[200010];
void solve()
{
int n;cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n;i++)
{
if(a[i]>b[i]) NO
else if(a[i]<b[i]&&b[i]-b[i%n+1]>1) NO
}
YES
}
signed main(void)
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--)solve();
}