結果

問題 No.43 野球の試合
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-06-13 22:50:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,692 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 31,952 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 21:53:51
合計ジャッジ時間 1,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 0 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 0 ms
4,372 KB
testcase_07 AC 6 ms
4,372 KB
testcase_08 AC 0 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:93:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   93 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:100:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  100 |                 scanf("%s", s[i]);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

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

#define READ_BUFSIZE ( 1024 )
#define READ_DELIMITER ( " " )

int count(char* pS, char c)
{
	int count = 0;
	for (int i = 0; i < strlen(pS); i++)
	{
		if (pS[i] == c)
			count++;
	}
	return(count);
}

int hantei(int N, char ps[6][7])
{
	int K = count(ps[0], 'o');
	if (K == N-1)
		return 1;

	int kachi[7] = { 0 };
	for (int i = 1; i < N; i++)
	{
		kachi[count(ps[i], 'o')] = 1;
	}

	int jun = 0;
	for (int j = K+1; j <= 6; j++)
	{
		if (kachi[j] == 1)
			jun++;
	}

	return(++jun);

}

void simulate(int N, char ps[6][7], int team, int shiai, int &junni)
{
	char p1[6][7] = { "" };
	char p2[6][7] = { "" };

	memcpy(p1, ps, 6 * 7);
	memcpy(p2, ps, 6 * 7);

	if (ps[team][shiai] == '-')
	{
		p1[team][shiai] = 'o';
		p1[shiai][team] = 'x';

		p2[team][shiai] = 'x';
		p2[shiai][team] = 'o';
	}

	if (shiai == N-1)
	{
		if (team == N-1)
		{
			//順位の判定をする
			int h = hantei(N, p1);
			if (h < junni)
				junni = h;

			h = hantei(N, p2);
			if (h < junni)
				junni = h;

			return;
		}
		shiai = 0;
		team++;

	}
	else
		shiai++;

	simulate(N, p1, team, shiai, junni);
	
	if (ps[team][shiai] == '-')
		simulate(N, p2, team, shiai, junni);

}

int main(int argc, char *argv[])
{

	int N = 0;
	scanf("%d", &N);

	char s[6][7] = { "" };
	int r[6][2] = { 0 }; //勝ち,残り

	for (int i = 0; i < N; i++)
	{
		scanf("%s", s[i]);
	}
/*
	for (int j = 0; j < N; j++)
	{
		if (s[0][j] == '-') //K君未試合分
		{
			s[0][j] = 'o'; //K君が勝ったことにする → だめらしい
			s[j][0] = 'x';

		}
	}
*/
	int junni = 6;
	simulate(N, s, 0, 0, junni);

	printf("%d\n", junni);



	return 0;

}

0