估计他说的是 '\n' 的问题
我就是真命天子,顺我者生,逆我者死!
#include <stdio.h> #include <stdlib.h> int cmp(const void *pa,const void *pb) { return *(int *)pa - *(int *)pb; } int main() { int m,n; while(scanf("%d%d",&n,&m) && (m||n)) { int i,j; int a[100005] = {0}; int b[100005] = {0}; for(i = 0;i<n;i++) scanf("%d",&a[i]); for(i = 0;i<m;i++) scanf("%d",&b[i]); qsort(a,n,4,cmp); qsort(b,m,4,cmp); i = j = 0; while(i<m && j<n) { if(b[i]<a[j]) break; else if(b[i]>a[j]) j++; else {i++;j++;} } if(i == m) printf("YES\n"); else printf("NO\n"); } return 0; }对于这个题我表示很纠结 总结一下 发这个帖子的原因是 因为我看错了题 题目说是数据个数位100000 而不是数据范围
#include<stdio.h> #include<stdlib.h> #define MAX 100000 int G[MAX], F[MAX], n, m; int cmp(const void * a, const void * b) { return *(int *)a - *(int *)b; } int work() { int i, j; qsort(G, n, sizeof(int), cmp); qsort(F, m, sizeof(int), cmp); for(i = 0, j = 0; i < n && j < m;) { if(G[i] < F[j]) { i++; continue; } else if(G[i] == F[j]) { i++; j++; continue; } else break; } return j == m; } int main() { int i; while(scanf("%d %d", &n, &m), n) { for(i = 0; i < n; scanf("%d", G + i++)); for(i = 0; i < m; scanf("%d", F + i++)); if(work()) printf("YES\n"); else printf("NO\n"); } return 0; }
#include<stdio.h> #include<stdlib.h> #define MAX 100000 int G[MAX], GF[MAX][2], n, fn; int cmp(const void * a, const void * b) { return *(int *)a - *(int *)b; } void format() { int i, j, k; qsort(G, n, sizeof(int), cmp); GF[0][0] = G[0]; GF[0][1] = 1; for(i = 1, j = 0; i < n; i++) { if(G[i] == GF[j][0]) GF[j][1]++; else { GF[++j][0] = G[i]; GF[j][1] = 1; } } fn = j + 1; } int work(int s) { int from, to, i; from = 0; to = fn - 1; while(from <= to) { i = (from + to) >> 1; if(GF[i][0] < s) from = i + 1; else if(GF[i][0] > s) to = i - 1; else { if(GF[i][1]) { GF[i][1]--; return 1; } return 0; } } return 0; } int main() { int i, s, m; while(scanf("%d %d", &n, &m), n) { for(i = 0; i < n; scanf("%d", G + i++)); format(); for(i = 0; i < m; i++) { scanf("%d", &s); if(!work(s)) break; } if(i == m) printf("YES\n"); else { printf("NO\n"); while(getchar() != '\n'); } } return 0; }