一道难题?主要是木有方法。
1041. Be Unique (20)
时间限制
20 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the second one who bets on 31 wins.
Input Specification:
Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=105) and then followed by N bets. The numbers are separated by a space.
Output Specification:
For each test case, print the winning number in a line. If there is no winner, print “None” instead.
Sample Input 1:
Input Specification:
Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=105) and then followed by N bets. The numbers are separated by a space.
Output Specification:
For each test case, print the winning number in a line. If there is no winner, print “None” instead.
Sample Input 1:
7 5 31 5 88 67 88 17
Sample Output 1:
31
Sample Input 2:
5 888 666 666 888 888
Sample Output 2:
None
本人解答:
//#include//#include #include
#include using namespace std; const int MAX_NUM_A = 10001; //const int MAX_NUM_B = 10000; int storage[MAX_NUM_A] = {0}; //list possibles; int possibles[MAX_NUM_A] = {0}; //0代表尚未存储,-1代表已经超额,其余代表输入时的顺序(第几个输入的这个数) //int sequence[MAX_NUM_B]; //list ary_list; /* inline void remove(int r) { //remove item from array ary_list.remove(r); } */ int main() { clock_t clockBegin, clockMid, clockEnd; int possibleN = 0; int N; //cin >> N; scanf("%u",&N); int input; clockBegin = clock(); for (int i=0; i > input; scanf("%u", &input); if(storage[input] == 0) { //尚未输入过这个数 storage[input] = i+1; //记录输入的顺序 //possibleN ++; //possibles.push_back(input); possibles[possibleN++] = input; } else { //重复了! //if(storage[input] > 0) //{ //possibles.remove(input); //possibleN --; //} storage[input] = -1; } } /* if(possibles.size() <= 0) { cout << "None"; return 0; } */ clockMid = clock(); //cout << clockMid - clockBegin << endl; printf("%un",clockMid - clockBegin); //int count = ary_list.size(); int min_seq = MAX_NUM_A; int min_val = -1; int i=0; while(i < possibleN) { int temp = storage[possibles[i]]; if(temp > 0) { //if(temp < min_seq) //{ min_seq = temp; min_val = possibles[i]; break; //} } //possibles.pop_front(); i ++ ; } clockEnd = clock(); //cout << clockEnd - clockMid << endl; printf("%un",clockEnd - clockMid); if(min_val != -1) { //cout << min_val; printf("%u",min_val); return 0; } //cout << "None"; printf("None"); return 0; }
知道结论是什么么?
结论是sscan比cin效率高很多!
One reply on “1041. Be Unique (20)”
line 36:if(storage[input] == 0)line 39:storage[input] = i+1; //记录输入的顺序line 52:storage[input] = -1;不知道为什么上面三行显示不正常,可能是语法加亮插件的bug.