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);
    }
    
  • 相关阅读:
    How to Install Linux, Apache, MySQL, PHP (LAMP) stack on CentOS 6 【Reliable】
    可以把一些常用的方法,写入js文件,引入html界面
    把功能写在方法里,函数化,方法化
    那些SQL语句
    Linux&shell之高级Shell脚本编程-创建菜单
    Linux&shell之高级Shell脚本编程-创建函数
    PHP isset()与empty()的使用区别详解
    如何打开mo文件并修改 PoEdit
    Linux&shell之如何控制脚本
    Linux&shell之显示数据
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12266526.html
Copyright © 2011-2022 走看看