程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU 1800:Flying to the Mars

HDU 1800:Flying to the Mars

編輯:C++入門知識

HDU 1800:Flying to the Mars


Flying to the Mars

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10817 Accepted Submission(s): 3469


Problem Description
\

In the year 8888, the Earth is ruled by the PPF Empire . As the pZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcHVsYXRpb24gZ3Jvd2luZyAsIFBQRiBuZWVkcyB0byBmaW5kIG1vcmUgbGFuZCBmb3IgdGhlIG5ld2Jvcm5zIC4gRmluYWxseSAsIFBQRiBkZWNpZGVzIHRvIGF0dGFjayBLc2Npbm93IHdobyBydWxpbmcgdGhlIE1hcnMgLiBIZXJlIHRoZSBwcm9ibGVtIGNvbWVzISBIb3cgY2FuIHRoZSBzb2xkaWVycyByZWFjaCB0aGUgTWFycyA/IFBQRgogY29udm9rZXMgaGlzIHNvbGRpZXJzIGFuZCBhc2tzIGZvciB0aGVpciBzdWdnZXN0aW9ucyAuIKGwUnVzaCChrSChsSBvbmUgc29sZGllciBhbnN3ZXJzLiChsFNodXQgdXAgISBEbyBJIGhhdmUgdG8gcmVtaW5kIHlvdSB0aGF0IHRoZXJlIGlzbqGvdCBhbnkgcm9hZCB0byB0aGUgTWFycyBmcm9tIGhlcmUhobEgUFBGIHJlcGxpZXMuIKGwRmx5ICGhsSBhbm90aGVyIGFuc3dlcnMuIFBQRiBzbWlsZXMgOqGwQ2xldmVyIGd1eSAhIEFsdGhvdWdoIHdlIGhhdmVuoa90IGdvdAogd2luZ3MgLCBJIGNhbiBidXkgc29tZSBtYWdpYyBicm9vbXN0aWN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l2ZSBudW1iZXIgTiBpbmRpY2F0aW5nIHRoZSBudW1iZXIgb2Ygc29sZGllcnMuKDA8PU48PTMwMDApPGJyPgpOZXh0IE4gbGluZXMgOlRoZXJlIGlzIG9ubHkgb25lIG5vbm5lZ2F0aXZlIGludGVnZXIgb24gZWFjaCBsaW5lICwgaW5kaWNhdGluZyB0aGUgbGV2ZWwgbnVtYmVyIGZvciBlYWNoIHNvbGRpZXIuKCBsZXNzIHRoYW4gMzAgZGlnaXRzKTs8YnI+CgoKIAo8YnI+CgpPdXRwdXQKCkZvciBlYWNoIGNhc2UsIG91dHB1dCB0aGUgbWluaW11bSBudW1iZXIgb2YgYnJvb21zdGlja3Mgb24gYSBzaW5nbGUgbGluZS4KCiAKPGJyPgoKU2FtcGxlIElucHV0Cgo8cHJlIGNsYXNzPQ=="brush:java;">4 10 20 30 04 5 2 3 4 3 4
Sample Output
1
2

題目說一把掃帚。高的可以教低的。做他的老師。低的當然是學生。問最少需要多少把掃帚。看同一個級別的最多有多少個。同一級別最多的就是需要掃帚的個數。典型的可以用hash做。。但是我不是。。




#include
#include
#include
#include
#include
#include

using namespace std;

const int maxn = 30000 + 50;

int n;
int a[maxn];
int ans;

int main()
{
    while(scanf("%d", &n) == 1 )
    {
        memset(a, 0, sizeof(a));
        int b;
        ans = -0x3f3f3f3f;
        int t = 1;
        int temp = 1;
        for(int i=1; i<=n; i++)scanf("%d", &a[i]);
        sort(a+1, a+n+1);
        if( n==1 )
            printf("1\n");
        else
        {
            for(int i=2; i<=n; i++)
            {
                if( a[i] == a[i-1] ){t++;temp = t;}
                else t = 1;
                if( temp>ans ){ans = temp;temp = 1;}
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}








  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved