Captain Flint and Crew Recruitment CodeForces - 1388A rat800

Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint’s task.

Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let’s define a positive integer x as nearly prime if it can be represented as p⋅q, where 1<p<q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2⋅3=6 and 2⋅5=10), but integers 1, 3, 4, 16, 17 or 44 are not.

Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.

Uncle Bogdan easily solved the task and joined the crew. Can you do the same?

Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.

Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1≤n≤2⋅105) — the number Flint guessed.

Output
For each test case print:

YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.

In the third test case, n=31=2⋅7+2⋅5+2⋅3+1: integers 14, 10, 6 are nearly prime.

In the fourth test case, n=36=5+2⋅3+2⋅5+3⋅5: integers 6, 10, 15 are nearly prime.

In the fifth test case, n=44=2⋅3+7+2⋅5+3⋅7: integers 6, 10, 21 are nearly prime.

In the sixth test case, n=100=2+2⋅5+3⋅11+5⋅11: integers 10, 33, 55 are nearly prime.

In the seventh test case, n=258=2⋅5+3⋅7+13⋅17+2⋅3: integers 10, 21, 221, 6 are nearly prime.
用最小的互质数6 10 15 来代替前三个数字,记得在重复使用是特殊判断一下

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 3e5+10;
int n;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        if(n<=30)
            printf("NO\n");
        else if(n==36||n==40||n==44)
            printf("YES\n 6 10 15 %d\n",n-31);
        else
            printf("YES\n 6 10 14 %d\n",n-30);
    }
    system("pause");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here's a possible Python implementation of the game: ```python import random def roll_dice(num_dice): """Rolls a given number of dice and returns their values.""" return [random.randint(1, 6) for _ in range(num_dice)] def play_round(num_players): """Plays a round of Ship of Fools with a given number of players.""" scores = [0] * num_players for i in range(num_players): print(f"Player {i+1}'s turn:") input("Press Enter to roll the dice...") dice = roll_dice(5) print(f"You rolled: {dice}") if 6 in dice and 5 in dice and 4 in dice: print("You have a ship, captain, and crew! Good job.") cargo = sum(d for d in dice if d not in [6, 5, 4]) scores[i] = cargo else: print("Sorry, you don't have a ship, captain, and crew.") max_score = max(scores) winners = [i+1 for i, score in enumerate(scores) if score == max_score] print(f"\nRound over. The highest cargo was {max_score}.") print(f"Player {winners[0]} is the winner!\n") return winners[0] def play_game(num_players): """Plays a full game of Ship of Fools with a given number of players.""" print(f"\nStarting a game of Ship of Fools with {num_players} players...\n") winner = None while winner is None: winner = play_round(num_players) print(f"Game over. Player {winner} wins!\n") # Example usage: play_game(3) ``` In this implementation, the `roll_dice` function generates a list of random values between 1 and 6, representing the dice rolls. The `play_round` function simulates one round of the game for a given number of players. Each player takes a turn rolling the dice and trying to get a ship, captain, and crew. If successful, their score for the round is the sum of the remaining dice values. If unsuccessful, their score for the round is zero. After all players have taken their turns, the winner of the round is the one with the highest score. The `play_game` function plays a full game of Ship of Fools with a given number of players, continuing until one player wins two rounds.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值