A.Strange Cake Game
对于小W,往下走最赚,对于小M往右走最赚,于是路线形成了个折线,直接对应竖坐标位置去看看横坐标符不符合要求即可
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
ll n,m;
cin>>n>>m;
ll k;
cin>>k;
ll ans=0;
while(k--)
{
ll x,y;
cin>>x>>y;
if(x<=y)
ans++;
}
cout<<ans<<endl;
}
B.Strange Madoka Game
将题目进行转化形成两个式子\(k1*x1+b1=m,k2*x2+b2=m\)
然后有\(k1*x1+b1=k2*x2+b2\)
随后左右模x2
有\((k1*x1+b1-b2)\)%\(x2=0\)
这里我取\(x2=4e8-1,x1=4e8\)
最后式子可转化成
\(k1\)%\(x2=(b2-b1)\)%\(x2\)
对于k1,他必须小于x2,否则\(k1*x2>1e17\),所以当\(b2-b1<=0,k1=b1-b2\),否则\(k1=x2-(b1-b2)\)
所以\(m=k1*x1+b1\)
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
//mt19937 rand(time(0));
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
ll t;
cin>>t;
ll x=4e8,y=(4e8-1);
while(t--)
{
cout<<"? "<<x<<endl;
cout.flush();
ll j;
cin>>j;
cout<<"? "<<y<<endl;
cout.flush();
ll k;
cin>>k;
cout<<"! ";
if(j==0&&k==0)
{
cout<<0<<endl;
}
else if(j==k)
{
cout<<j<<endl;
}
else
{
ll uo=(j-k)%y;
ll c=y-uo;
if(uo<=0)
c=abs(uo);
cout<<x*(c)+j<<endl;
}
}
}
C.Strange Homura Game
先将式子得出\(x1=m*k1+b1,x2=m*k2+b2\)
转化得\(x1-b1=m*k1,x2-b2=m*k2\)
现在只要使\(k1!=k2即可使答案m得出\)
这里取x最好取大于等于2e17的数,这样求出第一个\(k1*m\),
然后用\((k1*m-1)\),得出\(k2*m\)
这样保证\(k1=k2+1\),随后gcd即可
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
#include<time.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
ll x=((ll)1e17)+rnd()%(ll)(1e17);
ll t;
cin>>t;
while(t--)
{
ll j,k;
cout<<"? "<<x<<endl;
cout.flush();
cin>>j;
ll uo=x-j;//倍数
ll ko=uo-1;
cout<<"? "<<ko<<endl;
cout.flush();
cin>>k;
ll co=gcd(uo,ko-k);
cout<<"! "<<co<<endl;
}
}
标签:10,洛谷,cout,ll,SFMOI,k1,ans,x2,include
From: https://www.cnblogs.com/cjcf/p/18444972