【贪心】 【HDU 5821】 Ball

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5821

题解(1001):

http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-8-solutions-by-%E5%AD%A6%E5%86%9B%E4%B8%AD%E5%AD%A6/

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int a[1005], b[1005], ans[1005];
 5 
 6 int main(){
 7     int T;
 8     scanf("%d", &T);
 9     while(T--){
10         int n, c;
11         scanf("%d%d", &n, &c);
12         for(int i = 0; i < n; i++) scanf("%d", &a[i]);
13         for(int i = 0; i < n; i++) scanf("%d", &b[i]);
14         memset(ans, -1, sizeof(ans));
15         for(int i = 0; i < n; i++){
16             for(int j = 0; j < n; j++){
17                 if(b[j] != -1 && a[i] == b[j]){
18                     ans[i] = j+1;
19                     b[j] = -1;
20                     break;
21                 }
22             }
23         }
24         //for(int i = 0; i < n; i++) printf("%d ", ans[i]); printf("
");
25         while(c--){
26             int l, r;
27             scanf("%d%d", &l, &r);
28             sort(ans+l-1, ans+r);
29             //printf("l:%d, r:%d	:", l ,r);
30             //for(int i = 0; i < n; i++) printf("%d ", ans[i]); printf("
");
31         }
32         int f = true;
33         for(int i = 0; i < n; i++){
34             if(ans[i] != i+1){
35                 f = false;
36                 break;
37             }
38         }
39         if(f == true) puts("Yes");
40         else puts("No");
41     }
42 
43     return 0;
44 }
原文地址:https://www.cnblogs.com/miaowTracy/p/5763247.html