列表

详情


NC232086. Generate 7 Colors

描述

Albedo needs some pieces of 7 colors to paint PaiMonaLisa! Colors are numbered from 0 to 6. For color i, he needs exact a_i pieces.
Albedo is a master alchemist. In one operation, he can generate a sequence s of any length k. For the sequence , hold for . The i-th element indicates a piece of color s_i.
Please help Albedo find the minimum number of operations to generate exact a_i pieces for all 7 colors.


输入描述

The first line contains an integer  --- the number of test cases.
Each test case is described by 7 integers in one line --- the pieces Albedo needs for 7 colors respectively.

输出描述

For each test, output an integer in one line --- the minimum number of operations to generate exact a_i pieces for all 7 colors. If it's impossible to do it, output -1.

示例1

输入:

3
2 2 2 2 1 1 1
3 3 3 3 1 1 1
1 1 1 1 1 1 1000000000

输出:

1
2
-1

说明:

For test case 1, Albedo can use 1 operation and generate the sequence [0,1,2,3,4,5,6,0,1,2,3].
For test case 2, Albedo can use 2 operations and generate [0,1,2,3,4,5,6,0,1,2,3] and [0,1,2,3] respectively.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 353ms, 内存消耗: 1316K, 提交时间: 2021-12-19 16:00:50

#include<bits/stdc++.h>
using namespace std;
int _,a[7];
int main () {
	cin>>_;
	while (_--) {
		for (int i=0;i<7;i++) cin>>a[i];
		int f=1;
		for (int i=0;i<6;i++) if (a[i]<a[i+1]) f=0;
		if (!f) {
			cout<<"-1\n";
			continue;
		}
		cout<<max(1,a[0]-a[6])<<'\n';
	}
}

Python3 解法, 执行用时: 897ms, 内存消耗: 5496K, 提交时间: 2022-03-07 16:52:18

for _ in range(int(input())):
    a=list(map(int,input().split()))
    f=1
    for i in range(6,0,-1):
        if a[i]>a[i-1]:
            f=0
            break



    if f:
        print(max(1,a[0]-a[-1]))
    else:
        print(-1)

上一题