HDU 2574 HDOJ 2574 Hdu Girls' Day ACM 2574 IN HDU
生活随笔
收集整理的這篇文章主要介紹了
HDU 2574 HDOJ 2574 Hdu Girls' Day ACM 2574 IN HDU
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
MiYu原創, 轉帖請注明 : 轉載自?______________白白の屋????
?
因為 大于 1 << 16 的和數都能用 1 -- 1<<16 之間的素數表示, 不能表示的肯定是 素數了, 所以處理 1-- 1<<16之間的素數就可以了.
不過貌似這題的數據很弱沒有大于 1 << 16 的素數.?
?
?代碼
#include <iostream>#include <algorithm>#include <string>#include <set>#include <map>#include <utility>#include <queue>#include <stack>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;struct type{char name[30];int num;}a[1005];
const int MAX_PRIME = ?1 << 16;# define PRIME_NUM 35000int Primes[PRIME_NUM + 10] ;bool ?PrimeBuffer[MAX_PRIME];int _Count = 0;int GetPrimes (){ int i, j ; for (i = 2 ; i < MAX_PRIME ; i++) { if (PrimeBuffer[i] == 0) Primes[_Count++] = i ; for (j = 0 ; j < _Count && i * Primes[j] <= MAX_PRIME ; j++) { PrimeBuffer[i * Primes[j]] = 1 ; if (i % Primes[j] == 0) break ; } } free (PrimeBuffer) ; return _Count ;}inline bool scan_d(int &num) ?//整數輸入{char in;bool IsN=false;in=getchar();if(in==EOF) return false;while(in!='-'&&(in<'0'||in>'9')) in=getchar();if(in=='-'){ IsN=true;num=0;}else num=in-'0';while(in=getchar(),in>='0'&&in<='9'){num*=10,num+=in-'0';}if(IsN) num=-num;return true;}int main (){int T;GetPrimes ();scan_d(T);while ( T -- ) {int N;scan_d( N );int ma = -1;char mi[30] = "{";for ( int i = 0 ; i < N ; ++ i ) {scanf ( "%s",a[i].name);scan_d( a[i].num );int cnt = 0;for ( int j = 0 ; j < _Count && a[i].num > 1 ; ++ j ) {if ( a[i].num%Primes[j]==0 ) {while(a[i].num%Primes[j]==0){a[i].num /= Primes[j];}cnt++; ? ? ?}}if ( cnt == 0 ) cnt = 1; ?// 沒加這句也能A 說明沒有 1 和 超過1<<16的素數if ( ma < cnt ) { ma = cnt; strcpy ( mi, a[i].name ); }else if ( ma == cnt ) {?if ( strcmp ( a[i].name, mi ) < 0 )strcpy ( mi, a[i].name ); ? ??}}puts(mi);}return 0;}
?
轉載于:https://www.cnblogs.com/MiYu/archive/2010/11/16/1878824.html
總結
以上是生活随笔為你收集整理的HDU 2574 HDOJ 2574 Hdu Girls' Day ACM 2574 IN HDU的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Map是不是集合?
- 下一篇: Boost::Regex 使用方法 (英