当前位置: 代码迷 >> 综合 >> Kattis Bijele
  详细解决方案

Kattis Bijele

热度:42   发布时间:2023-12-12 09:34:02.0

此文章可以使用目录功能哟↑(点击上方[+])

 Kattis <Bijele>

Accept: 0    Submit: 0
Time Limit: 1 second    Memory Limit : 1024 MB

 Problem Description

Mirko has found an old chessboard and a set of pieces in his attic. Unfortunately, the set contains only white pieces, and apparently an incorrect number of them. A set of pieces should contain:

  • One king
  • One queen
  • Two rooks
  • Two bishops
  • Two knights
  • Eight pawns

Mirko would like to know how many pieces of each type he should add or remove to make a valid set.

 Input

The input consists of 6 integers on a single line, each between 0 and 10 (inclusive). The numbers are, in order, the numbers of kings, queens, rooks, bishops, knights and pawns in the set Mirko found.

 Output

Output should consist of 6 integers on a single line; the number of pieces of each type Mirko should add or remove. If a number is positive, Mirko needs to add that many pieces. If a number is negative, Mirko needs to remove pieces.

 Sample Input

0 1 2 2 2 7
2 1 2 1 2 1

 Sample Output

1 0 0 0 0 1
-1 0 0 1 0 7

 Problem Idea

解题思路:

【题意】

国际象棋中有下述6种棋子:

1.一个国王

2.一个皇后

3.两个车

4.两个象

5.两个马

6.八个卒

现在给你棋盘上这6种棋子的个数,问为了使棋子数量合法,每种棋子需要增加或减少多少个

输出的数为正表示增加,为负表示减少

【类型】
暴力

【分析】

由于每种棋子的合法数量已经告诉我们,这样就避免了没有接触过国际象棋的人而无法下手的局面

所以,我们要做的就是将实际数量与合法数量一一比较就可以了

【时间复杂度&&优化】
O(6)

题目链接→Kattis <Bijele>

 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 6;
const int M = 100005;
const int inf = 1000000007;
const int mod = 10007;
int ans[N]={1,1,2,2,2,8},s[N];
int main()
{int i;for(i=0;i<N;i++){scanf("%d",&s[i]);printf("%d%c",ans[i]-s[i],i!=N-1?' ':'\n');}return 0;
}
菜鸟成长记