結果

問題 No.7 プライムナンバーゲーム
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-04-17 00:18:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,524 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 33,680 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:13:13
合計ジャッジ時間 1,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,688 KB
testcase_01 AC 1 ms
6,692 KB
testcase_02 AC 4 ms
6,688 KB
testcase_03 AC 1 ms
6,688 KB
testcase_04 AC 0 ms
6,688 KB
testcase_05 AC 1 ms
6,692 KB
testcase_06 AC 2 ms
6,692 KB
testcase_07 AC 1 ms
6,696 KB
testcase_08 AC 1 ms
6,692 KB
testcase_09 AC 2 ms
6,692 KB
testcase_10 AC 1 ms
6,688 KB
testcase_11 AC 2 ms
6,692 KB
testcase_12 AC 3 ms
6,692 KB
testcase_13 AC 3 ms
6,688 KB
testcase_14 AC 4 ms
6,692 KB
testcase_15 AC 4 ms
6,692 KB
testcase_16 AC 3 ms
6,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define READ_BUFSIZE ( 16 )
#define READ_DELIMITER ( " " )


//標準入力取得(1行)

int GetStdin( char* pszStr, int lMaxLen )
{
	int lLen = 0;

    memset( pszStr, 0, lMaxLen );
    if( fgets( pszStr, lMaxLen, stdin ) )
    {
	    lLen = strlen( pszStr );
	    if( lLen >= 1 )
	    {
			if( pszStr[ lLen - 1 ] == 0x0A )
			{
				pszStr[ lLen - 1 ] = 0;
				lLen--;
			}
		}
	}
	
	return( lLen );
}

//標準入力を取得
//区切り文字で区切られている文字列を取り出す
//取り出した文字列のポインタをポインタ配列にセットする (数値型)
int split(char *pszStr, int lStrMax, const char *pszDelim, int *palOutList) {
    char *pszToken;
    int count = 0;
    char *pszNext_token = 0;
	int lLen = 0;
	int lNum = 0;

    memset( pszStr, 0, lStrMax );
    lLen = GetStdin( pszStr, lStrMax );
    
	if( lLen > 0 )
	{

	    pszToken = strtok( pszStr, pszDelim );

	    while ( pszToken != NULL ) 
	    {
            *palOutList = atoi( pszToken );
			lNum++;
//	        pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
		    pszToken = strtok( NULL, pszDelim );
			palOutList++;
	    }
	}
    return lNum;
}


bool isSosu(int N)
{
	//#include <math.h>

	if( N == 0 || N == 1)
		return false;

	if( N == 2 )
		return true;

	if( N % 2 == 0 )
		return false;

	bool isSosu = true;
	//for( int i = 3; i < N; i +=2 )
	for( int i = 3; i <= sqrt((float)N); i +=2 )  
	{
		if( N % i == 0 )
		{
			isSosu = false;
			break;
		}

	}
	return( isSosu );
}

int makeSosu(int* pS, int N)
{
	int count = 0;
	for( int i = 1; i <= N; i++ )
	{
		if( isSosu( i ) )
		{
			pS[count] = i;
			count++;
		}
	}
	return( count );
}



bool game( int N, int* pS, int Scount, bool my )
{
	int Shouhai[10000+1] = {0};
	Shouhai[4] = 1;
	bool bWin = false;

	for( int i = 5; i <= N;i++ )
	{
		for( int j = 0; j < Scount && pS[j] <= i; j++ )
		{
			if( i-pS[j] > 1 && Shouhai[ i-pS[j] ] == 0 )
			{
				Shouhai[i] = 1;
				break;

			}
		}
	}

	if( Shouhai[N] == 1 )
		bWin = true;


	return( bWin );

}


int main(int argc, char *argv[]) 
{
	//10000の場合、素数の数は1230個
	
	char szRead[READ_BUFSIZE] = "";
	//char* psOutbuf[10000] = { 0 };
	int lInput[2] = {0};

	split( szRead, READ_BUFSIZE, READ_DELIMITER, lInput );

	int N = lInput[0];
	int S[2000] = {0};
	bool my = true;

	int count = makeSosu( S, N );


	if( game( N, S, count, my ) )
		printf( "Win\n" );
	else
		printf( "Lose\n" );
	
	return 0;

}

0