AtCoder B - Pizza

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

We have a circular pizza.
Takahashi will cut this pizza using a sequence AA of length NN, according to the following procedure.

  • First, make a cut from the center in the 1212 o'clock direction.
  • Next, do NN operations. The ii-th operation is as follows.
    • Rotate the pizza A_iAi​ degrees clockwise.
    • Then, make a cut from the center in the 1212 o'clock direction.

For example, if A=(90,180,45,195)A=(90,180,45,195), the procedure cuts the pizza as follows.

Find the center angle of the largest pizza after the procedure.

Constraints

  • All values in input are integers.
  • 1 \le N \le 3591≤N≤359
  • 1 \le A_i \le 3591≤Ai​≤359
  • There will be no multiple cuts at the same position.

Input

Input is given from Standard Input in the following format:

NN
A_1A1​ A_2A2​ \dots… A_NAN​

Output

Print the answer as an integer.


Sample Input 1 Copy

Copy

4
90 180 45 195

Sample Output 1 Copy

Copy

120

This input coincides with the example in the Problem Statement.
The center angle of the largest pizza is 120120 degrees.


Sample Input 2 Copy

Copy

1
1

Sample Output 2 Copy

Copy

359

Sample Input 3 Copy

Copy

10
215 137 320 339 341 41 44 18 241 149

Sample Output 3 Copy

Copy

170

 

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
inline int read()
{
	int x = 0, y = 1;
	char c = getchar();
	while(c < '0' || c > '9')
	{
		if(c == '-')  y = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9')
		x = x * 10 + c - '0', c = getchar();
	return x * y;
}
 
typedef unsigned long long LL;

typedef pair<LL, LL> PII;
 
const int N = 1e6 + 10;

int n, q, res, m, cnt, maxm;
bool f[N];


signed main()
{
	n = read();
	f[0] = true;
	for(int i = 1; i <= n; i ++ )
	{
		int x;
		x = read();
		res += x; res %= 360;
		f[res] = true;
	}
	for(int i = 0; i <= 360; i ++ )
	{
		if(f[i % 360])  
		{
			maxm = max(maxm, cnt);
			cnt = 0;
		}
		cnt ++;
	}
	cout << maxm << endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分披萨 题目描述 在给定 m个人的情况下,有 n块比萨。每块比萨都有一个分数。我们希望将比萨分配给每个人,使得每个人得分尽可能多。分数可以为 0。 例如,在给定 3 个人和 3 块比萨的情况下,比萨的得分分别为 5, 4, 7,我们可以将比萨分配为: (5)、(4)、(7),以便每个人分别得到 5, 4, 7 分。 给定 m 个人和 n 块比萨,每块比萨的得分以及每个人对比萨的偏好 (可能有中性,喜欢或者讨厌),你的任务是计算每个人得到的最大分数。 输入格式 输入包含多组测试数据。 每组测试数据的第一行包含两个整数 n(1≤n≤1000) 和 m(1≤m≤100) — 分别表示比萨的数量和人数。第二行包含 n 个整数 a1,a2…an(1≤ai≤1000) — 表示每块比萨的分数。接下来的 m 行每行包含 n 个整数 b1,b2…bn(−1≤bi≤1) — 表示每个人喜欢(1),中性(0)或者讨厌(−1)每块比萨。 输入保证对于每组测试数据至少存在一个人喜欢比萨。 当 n = m = 0 时,表示输入结束。 输出格式 对于每组测试数据,输出 m 行。每行包含一个整数,表示每个人得到的最大分数。 样例输入 3 3 5 4 7 1 0 -1 0 1 0 1 0 0 3 3 4 7 8 -1 0 1 1 -1 0 1 0 0 样例输出 5 4 7 4 7 8 ```python # 代码: while True: n, m = list(map(int, input().split())) if n == 0 and m == 0: break pizzas = list(map(int, input().split())) preferences = [list(map(int, input().split())) for _ in range(m)] scores = [0] * m for i in range(n): max_score = 0 for j in range(m): if preferences[j][i] == 1: max_score = max(max_score, pizzas[i]) elif preferences[j][i] == 0: max_score = max(max_score, pizzas[i] // 2) for j in range(m): if preferences[j][i] == 1 or (preferences[j][i] == 0 and max_score == pizzas[i] // 2): scores[j] += max_score for score in scores: print(score) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值