洛谷 P4613 [COCI2017-2018#5] Olivander

时空限制1000ms / 64MB

题目描述

Harry Potter has damaged his magic wand in a fight with Lord Voldemort. He has decided to get a new wand in Olivander's wand shop. On the floor of the shop, he saw ​N wands and ​N wand boxes. The lengths of the wands are, respectively, X_1X1​ ,X_2X2​ ...​X_nXn​ , and the box sizes are Y_1Y1​ ,​Y_2Y2​ ...Y_nYn​ . A wand of length ​X can be placed in a box of size ​Y if ​X ≤ ​Y . Harry wants to know if he can place all the wands in boxes so that each box contains exactly one wand. Help him solve this difficult problem.

输入输出格式

输入格式:

The first line of input contains the positive integer ​N (1 ≤ ​N ≤ 100), the number from the task. The second line contains ​N positive integers ​X_iXi​ (1 ≤ ​X_iXi​ ≤ 10^9109​ ), the numbers from the task. The third line contains ​N positive integers ​X_iXi​ (1 ≤ X_iXi​ ≤ 10^9109​​ ), the numbers from the task.

输出格式:

If Harry can place all the wands in boxes, output “DA” (Croatian for yes), otherwise output “NE” (Croatian for no).

有点蒟的翻译:

题目描述

哈利波特在与伏地魔的斗争中损坏了他的魔杖。他决定在Olivander的魔杖商店买一把新魔杖。在商店的地板上,他看到了N个魔杖和N个魔杖盒。魔杖的长度分别是X_1X1 ,X_2X2 ...X_nXñ ,盒子大小是 Y_1ÿ1 ,Y_2ÿ2 ...Y_nÿñ 。如果X≤Y,可以将长度为X的棒放在尺寸为Y的盒子中。Harry想知道他是否可以将所有魔杖放在盒子里,这样每个盒子里只包含一根魔杖。帮助他解决这个难题。

输入输出格式

输入格式:

第一行输入包含正整数N(1≤N≤100),即任务中的数字。第二行包含N个正整数X_IX我 (1≤X_IX我 ≤ 10 ^ 91 09),来自任务的数字。第三行包含N个正整数X_IX我 (1≤ X_IX我 ≤ 10 ^ 91 09),来自任务的数字。

输出格式:

如果哈利可以将所有魔杖放在盒子里,输出“DA”(克罗地亚语为肯定),否则输出“NE”(克罗地亚语为否)。

输入样例1:

3

7 9 5

6 13 10

输出样例1:

DA

输入样例2:

4

5 3 3 5

10 2 10 10

输出样例2:

NE

说明

在总分为60%的测试用例中,它将保持N≤9。

澄清第一个测试用例:

哈利可以将魔杖放在盒子里。例如,他可以将长度为5的棒放入尺寸为6的盒子中,将长度为7的棒放入一个尺寸为13的盒子中,将长度为9的棒放入一个10号的盒子中。

澄清第二个测试用例:

哈利不能将魔杖放在盒子里,因为2号盒子不适合任何魔杖。

有点贪的感觉,加上了一个忘记从哪里搞得快读。

就是短的盒子放短的魔棒。排一下序就好啦

代码:

#include

using namespacestd;


int read()

{

    int x=0,f=1;

    char c=getchar();

    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}

   while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}

    return x*f;

}

int main() {

      int n;

      n=read();

      int x[111],y[111];

      for(int i=1; i<=n; i++)

           x[i]=read();

      for(int i=1; i<=n; i++)

           y[i]=read();

      sort(x+1,x+1+n);

      sort(y+1,y+1+n);

      for(int i=1; i<=n; i++) {

           if(y[i]

                 cout<<"NE";

                 return 0;

           }

      }

      cout<<"DA";

      return 0;

}

你可能感兴趣的:(洛谷 P4613 [COCI2017-2018#5] Olivander)