zoukankan      html  css  js  c++  java
  • hdu 2034 人见人爱AB

    这题挺水的但是我错了好多次,总结一下主要是有以下几点:
    1.代码鲁棒性不好,题目虽说是0 0结束,但也有EOF的情况,单判0 0结果会TLE。
    2.对n = 0的情况判断的太靠前导致还没输入就进入到了下一次循环结果就让下一次的输入出错了。
    3.(第一次忘了排序了(太蠢了))。

    #include<cstdio>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #define TP 233333333333333
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    const int maxn = 105;
    ll arr1[maxn];
    bool check(int n);
    void quickSort(int begin, int end);
    int main(void) {
    	int n, m;
    	while(cin >> n >> m && (n || m)) {
            memset(arr1, 0, maxn*sizeof(ll));
            /*********************************
            if (!n) { //n为0即空集
    			cout << "NULL\n";
    			continue;
    		}
    		第一次的判断放到这了,导致下面m个元素都没
    		输进去,留到了输入队列里
    		**********************************/
    		for (int i = 0; i<n; i++)
    			scanf("%lld", &arr1[i]);
    		quickSort(0, n-1);
    		for (int i = 0; i<m; i++) {
    			ll num;
    			scanf("%lld", &num);
    			for (int j = 0; j<n; j++) 
    				if (arr1[j] == num) {
    					arr1[j] = TP;//标记应该被减掉的元素
    					break;
    				}
    		}
            if (!n) { //n为0即空集
    			cout << "NULL\n";
    			continue;
    		}
    		if (check(n))
    			cout << "NULL";
    		cout << endl;
    	}
        return 0;
    }
    bool check(int n){
    	bool ok = true;
    	for (int i = 0; i<n; i++)
    		if (arr1[i] != TP) {
    			printf("%lld ", arr1[i]);//输出没有被标记的元素
    			ok = false;
    		}
    	return ok;
    }
    void quickSort(int begin, int end) {
    	if (begin >= end)
    		return;
    	int start = begin;
    	for (int i = begin; i<end; i++)
    		if (arr1[i] <= arr1[end])
    			swap(arr1[start++], arr1[i]);
    	swap(arr1[start], arr1[end]);
    	quickSort(begin, start-1);
    	quickSort(start+1, end);
    }
    
  • 相关阅读:
    Sql Server常见错误
    sql server复制需要有实际的服务器名称才能连接到服务器
    学习WCF必备网址
    利用Httphandler、UserControl 输出HTML片段
    SQL点滴—性能分析之执行计划
    我的WCF开发框架简化版及基于NET.TCP传输方式的实现
    数据库优化建议
    实现jQuery扩展总结
    【模板】zkw线段树
    洛谷 P1960 列队
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12266526.html
Copyright © 2011-2022 走看看