A I Wanna Be the Guy
解题思路
直接用一个set,最后判断一下是否有n个数。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
typedef vector<int> vi;
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e6+5;
int n;
set<int> a;
int main()
{
int t,x,y;
cin >> n;
cin >> x;
rep(i,1,x)
{
cin >> t;
a.insert(t);
}
cin >> y;
rep(i,1,y)
{
cin >> t;
a.insert(t);
}
if(a.size()==n)
{
cout <<"I become the guy."<<endl;
}
else
{
cout <<"Oh, my keyboard!"<<endl;
}
return 0;
}
B. Chat Online
解题思路
用一个数组标记固定的a,b,然后枚举k,暴力搜索c+k,d+k。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
typedef vector<int> vi;
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e6+5;
int p,q,l,r;
int ff[20005];
int a,b,c[20005],d[20005];
int main()
{
int re =0 ;
cin >> p>>q>>l>>r;
rep(i,1,p)
{
cin >> a>>b;
for(int j=a;j<=b;j++)
{
ff[j]++;
}
}
rep(i,1,q)
{
cin >> c[i]>>d[i];
}
for(int k=l;k<=r;k++)
{
int ct =0;
rep(i,1,q)
{
if(ct) break;
for(int j=c[i]+k;j<=d[i]+k;j++)
{
if(ff[j])
{
ct=1;
break;
}
}
}
if(ct) re++;
}
cout << re<<endl;
return 0;
}
C. 24 Game 简单构造
解题思路
首先判断奇偶:
奇数:可以知道5个数1,2,3,4,5可以组成24,然后其他有偶数个,分别相减得1。
偶数:可以知道4个数1,2,3,4可以组成24,然后其他的数有偶数个,分别相减得1。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
typedef vector<int> vi;
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e6+5;
int main()
{
int n;
cin >> n;
if(n<4)
{
cout << "NO"<<endl;
return 0;
}
cout << "YES"<<endl;
if(n%2)
{
int ct = (n-5)/2;
while(n>5)
{
cout << n << " - " <<n-1<<" = "<< 1<<endl;
n-=2;
}
cout << "3 * 5 = 15"<<endl;
cout << "2 * 4 = 8"<<endl;
cout << "8 + 15 = 23"<<endl;
cout << "23 + 1 = 24"<<endl;
for(int i=0;i<ct;i++)
{
cout << "24 * 1 = 24"<<endl;
}
}
else
{
int ct = (n-4)/2;
while(n>4)
{
cout << n << " - " <<n-1<<" = "<< 1<<endl;
n-=2;
}
cout << "3 * 4 = 12"<<endl;
cout << "12 * 2 = 24"<<endl;
cout << "24 * 1 = 24"<<endl;
for(int i=0;i<ct;i++)
{
cout << "24 * 1 = 24"<<endl;
}
}
return 0;
}