水題 第五站 HDU Ignatius and the Princess IV
剛開始看到這個題目覺得簡單得不行,考慮是將數字存入陣列,然後再進行遍歷,可以考慮一下這樣的複雜度是n^2,我覺得思路很清晰就沒敲程式碼,看自己去年提交過就看了下自己當時的程式碼,附當時程式碼
#include<iostream>
#include<stdio.h>
#include<string.h>
#define M 50000
using namespace std;
int tem,b[M];
int main(){
int n,i,j;
while(scanf("%d",&n)!=EOF){
memset (b,0,sizeof(b));
for(i=0;i<n;i++){
scanf("%d",&tem);
b[tem]++;
if(b[tem]>=(n+1)/2)
j=tem;
}
printf("%d\n",j);
}
return 0;
}
簡單好多,現在覺得n^2的思路肯定會超時,將陣列的下標和存的數交換一下位置,程式碼一下簡單了好多= =佩服當時的自己。
相關推薦
水題 第五站 HDU Ignatius and the Princess IV
剛開始看到這個題目覺得簡單得不行,考慮是將數字存入陣列,然後再進行遍歷,可以考慮一下這樣的複雜度是n^2,我覺得思路很清晰就沒敲程式碼,看自己去年提交過就看了下自己當時的程式碼,附當時程式碼 #include<iostream> #include<stdio.h&g
水題 第五站 HDU Max Sum Plus Plus
畢竟自己還是菜得不行,這個題目是從n個數字中選出m個不相交字串,使其和最大,話說這個題目的理解就反覆了好幾次= =,心想這不就是選出m個最大字串,然後和不就是最大嗎?然而還有不相交= =!所以完全沒有思路 網上的思路,動態規劃一個式子幾乎讓我抓狂= =,大神們的抽象思維能力好強= =,
水題 第八站 HDU Train problem II
參考部落格 http://www.cnblogs.com/MisdomTianYa/p/6581898.html http://www.cnblogs.com/kuangbin/archive/2012/03/21/2410519.html 卡特蘭
水題 第六站 HDU Safecracker
#include <iostream> #include <stdio.h> #include <math.h> #include <algorithm> #include <string.h> #include <map&g
水題 第四站 HDU 1003 Max Sum
本年度動態規劃的第一道題目,完美不會。以前做過,思路也不是自己想的,大概也一知半解,這次的思路也不是自己想的。大概是忘記了動態規劃演算法,覺得這個題目不太像動態規劃 解題思路:從第一個數依次與後面的數相加,大於等於0則累加,小於0從當前位置往後加。這部分的程式碼很容易出錯= = 上程
水題 第四站 HDU A + B Problem II
一道很簡單的題目讓我做得噁心無比,大數問題,不熟悉java,還是用C++寫吧。顯然需要用到字串,然後再將字串中的數字轉化為整數型別進行加法運算。去年做類似題目的時候還只知其然不知其所以然,現在明白了為什麼不能直接讀入陣列。 然而時隔一年也忘記了思路,加上當時沒有總結過,只是仿照程式碼敲
HDU Ignatius and the Princess III (母函數)
tex namespace class .net author def urn rst isp Problem Description "Well, it seems the first problem is too easy. I will let you know h
[ACM] hdu 1029 Ignatius and the Princess IV (動歸或hash)
inner other for each sam 代碼 test case break accep bre Ignatius and the Princess IV Time Limit : 2000/1000ms (Java/Other) Memory Li
hdu-1029-Ignatius and the Princess IV
utility scrip freopen auth bsp author div 鏈接 amp 題目鏈接 1 /* 2 Name:hdu-1029-Ignatius and the Princess IV 3 Copyright:
HDU 1029 Ignatius and the Princess IV (map的使用)
left pass http sample ace nta say limit har 傳送門: http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit:
HDU 1029 Ignatius and the Princess IV
each ica mina too bits eas inner urn cas Ignatius and the Princess IV "OK, you are not too bad, em... But you can never pass the next t
HDU-1029-Ignatius and the Princess IV(dp)
Ignatius and the Princess IV Problem Description "OK, you are not too bad, em... But you can never pa
Ignatius and the Princess IV HDU - 1029
弱弱的吐槽一下QAQ為什麼這題是dp啊 注意一下不能為了節約在出現ans的時候直接break。。。這時候沒讀取的數字會被當做下一個n接著用 #include<stdio.h> #include<string.h> int p[1000000]; int ma
hodj 1029 Ignatius and the Princess IV
題目來源:http://acm.hdu.edu.cn/showproblem.php?pid=1029 直接開一個大點的陣列,資料竟然過了 hdoj 1029 Ignatius and the Princess IV 題目大意:找出數列中特殊的數,特殊的數為出現次數大於(n+2)/
HDU1029-Ignatius and the Princess IV
Problem Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number
Ignatius and the Princess IV
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N inte
水題 第四站 NYOJ Dinner
ace math tdi 超時 scan 忘記 字符 sca 水題 同樣感覺受到了貪心的欺騙,使用C++的string寫的,果斷超時,忘記了strcmp這個比較字符串的函數 我的代碼 1 #include <iostream> 2 #include <
水題 第三站 How many prime numbers
判斷素數,C++程式設計課本中的程式碼,需要掌握還有值得注意的一些小細節。 bool prime(int r) { if(r==2||r==3) return true; else { for(int i=2; i<=sq
水題 第三站 最小公倍數
看到這個題,完全是暴力的想法,後來超時稍稍做了寫優化,然而還是超時。原來用到了最大公約數的求法,就積累下這個小知識點。 int gcd (int x, int y) { while(x!=y) { if(x>y) x=x-
HDU 1028 Ignatius and the Princess III dp
cep 大數 style code 代碼 des for each 狀態轉移方程 遞推 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 一道經典題,也是算法設計與分析上的一道題,可以用遞推,動態規劃,母函數求解,我用的