R3 题解
dyz20120726 · · 个人记录
WMC 的 gold
Sol
此题一看就是一道贪心,答案是最大值的平方。
但要注意的是当最大值是第一个时,答案是最大值乘以第二大的值。
Code
#include <bits/stdc++.h>
using namespace std;
pair<int,int> a[1000005];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].first;
a[i].second=i;
}
sort(a+1,a+n+1);
if(a[n].second==1) cout<<1ll*a[n].first*1ll*a[n-1].first;
else cout<<1ll*a[n].first*1ll*a[n].first;
return 0;
}
WMC 的 pie
Sol
规律题,答案是x^y。
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int T;
cin>>T;
while(T--){
int x,y;
cin>>x>>y;
cout<<(x xor y)<<"\n";
}
return 0;
}
WMC 的 cat I
Sol
规律题,答案是abs(x)+abs(y)+1。
但注意,当x=0,y=0时,答案是0。
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long x,y;
cin>>x>>y;
if(x==0&&y==0)
{
cout<<0;
return 0;
}
cout<<abs(x)+abs(y)-1;
return 0;
}
WMC 的 generals
Sol
规律题,根据
Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
string a,b;
cin>>a>>b;
char c=a[a.size()-1],d=b[b.size()-1];
if(int(c-'0')*int(d-'0')%2) cout<<"XYC wins!!!\n";
else cout<<"WMC wins!!!\n";
}
return 0;
}
WMC 的 dinosaur
Sol
小恐龙的战斗力为
Code
#include<bits/stdc++.h>
using namespace std;
int n,x,k,a=1,b=1,c=2,mod=1e9+7;
int gcd(int x,int y)
{
if(x<y)
{
swap(x,y);
}
if(!y)
{
return x;
}
return gcd(y,x%y);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
k=gcd(k,x);
}
if(k<3)
{
cout<<1;
}
else
{
k-=3;
while(k--)
{
a=b;
b=c;
c=a+b;
c%=mod;
}
cout<<c;
}
}