Note
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.
题意:给你一个数 N 意味着有 1 至 N 个关卡,然后 每行第一个数 p 代表后面有 p 个整数跟随。 每个整数代表 其 能过的关卡的编号。
而现在有两组编号,题目就是要求我们把两组编号合起来,看里面是否能有 1 至 N 所有的数。
如果有,则输出“I
become the guy.” 否则输出Oh,
my keyboard!
懂题意后这题就简单了,水掉就是!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <ostream>
#include <string>
#include <cstdlib>
#include <cmath>
#define PI 3.141592653
using namespace std;
int n;
int p,q;
int a[1000]; //用以标记
int main( )
{
cin>>n;
for(int i = 0;i <= n; i++)
{
a[i]=1; //初始化
}
cin>>p;
int x;
while(p--)
{
scanf("%d",&x);
a[x]=0;
}
cin>>q;
while(q--)
{
scanf("%d",&x);
a[x]=0;
}
int judge=0;
for(int i = 1;i <= n; ++i)
{
judge=judge+a[i];
}
if(judge)
cout<<"Oh, my keyboard!"<<endl;
else
cout<<"I become the guy."<<endl;
return 0;
}
题意:给你 N 个固定的区间,M 个可以滑动的区间 且滑动的长度 t 可为[L,R]中的任意值。问在[ L , R ] 中有多少个 t 可以使得“ 滑动区间与固定区间有交集(在一个点上相交也算)”
所以。。。。暴力即可。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <ostream>
#include <string>
#include <cstdlib>
#include <cmath>
#define PI 3.141592653
using namespace std;
int p,q,l,r;
int vis[55][2];
int main( )
{
cin>>p>>q>>l>>r;
int a,b;
int kis[1100];
memset(kis,0,sizeof(kis));
for(int i = 0;i < p; i++)
{
scanf("%d%d",&a,&b);
vis[i][0]=a;
vis[i][1]=b;
}
int judge=0;
while(q--)
{
scanf("%d%d",&a,&b);
for(int i = l;i <= r; i++)
{
if(kis[i]==0)
for(int j = 0;j < p; j++)
{
if(a+i==vis[j][1]||a+i==vis[j][0]||b+i==vis[j][1]||b+i==vis[j][0])
{
kis[i]=1;
break;
}
else if(b+i>vis[j][1]&&a+i<vis[j][1])
{
kis[i]=1;
break;
}
else if(b+i>vis[j][0]&&a+i<vis[j][0])
{
kis[i]=1;
break;
}
else if(b+i<vis[j][1]&&a+i>vis[j][0])
{
kis[i]=1;
break;
}
}
}
}
for(int i = l; i <= r; i++)
{
judge+=kis[i];
}
cout<<judge<<endl;
return 0;
}
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of n integers: 1,?2,?...,?n.
In a single step, you can pick two of them, let‘s denote them a and b,
erase them from the sequence, and append to the sequence either a?+?b, or a?-?b,
or a?×?b.
After n?-?1 steps there is only one number left. Can you make this number equal to 24?
Output
If it‘s possible, print "YES" in the first line. Otherwise, print "NO"
(without the quotes).
If there is a way to obtain 24 as the result number, in the following n?-?1 lines
print the required operations an operation per line. Each operation should be in form: "a op b = c".
Where a and b are the numbers you‘ve picked at this
operation; op is either "+", or "-",
or "*";c is the result of corresponding operation. Note,
that the absolute value of c mustn‘t be greater than 1018.
The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces.
If there are multiple valid answers, you may print any of them.
Sample test(s)
output
YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24
题意:从 1 至 N 个数取两个数,用“ + ”,“ - ”,“ * ”进行运算,并把得到的结果加到原来的数中。如此进行N-1次操作,凑出24即可。
一个找规律的题目。。。找到规律后就简单了。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <ostream>
#include <string>
#include <cstdlib>
#include <cmath>
#define PI 3.141592653
using namespace std;
int n;
int main( )
{
cin>>n;
if(n<4)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
if(n%2==0)
{
printf("2 * 3 = 6\n");
printf("6 * 4 = 24\n");
printf("1 * 24 = 24\n");
for(int i = 5;i < n; i+=2)
{
printf("%d - %d = 1\n",i+1,i);
printf("1 * 24 = 24\n");
}
}
else
{
printf("4 * 5 = 20\n");
printf("3 + 20 = 23\n");
printf("23 + 2 = 25\n");
printf("25 - 1 = 24\n");
for(int i = 6; i< n; i+=2)
{
printf("%d - %d = 1\n",i+1,i);
printf("1 * 24 = 24\n");
}
}
}
return 0;
}
如有BUG,欢迎指出!