Codeforces Round #532 (Div. 2)- A(思维)
This morning, Roman woke up and opened the browser with nn opened tabs numbered from 11 to nn. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every kk-th (2≤k≤n−12≤k≤n−1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be bb) and then close all tabs with numbers c=b+i⋅kc=b+i⋅k that satisfy the following condition: 1≤c≤n1≤c≤n and ii is an integer (it may be positive, negative or zero).
For example, if k=3k=3, n=14n=14 and Roman chooses b=8b=8, then he will close tabs with numbers 22, 55, 88, 1111 and 1414.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it ee) and the amount of remaining social network tabs (ss). Help Roman to calculate the maximal absolute value of the difference of those values |e−s||e−s| so that it would be easy to decide what to do next.
Input
The first line contains two integers nn and kk (2≤k<n≤1002≤k<n≤100) — the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of nn integers, each of them equal either to 11 or to −1−1. The ii-th integer denotes the type of the ii-th tab: if it is equal to 11, this tab contains information for the test, and if it is equal to −1−1, it's a social network tab.
Output
Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types |e−s||e−s|.
Examples
input
Copy
4 2
1 1 -1 1
output
Copy
2
input
Copy
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
output
Copy
9
Note
In the first example we can choose b=1b=1 or b=3b=3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e=2e=2 and s=0s=0 and |e−s|=2|e−s|=2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
思路:按照题目去模拟即可,关闭可以认为是忽略的
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[105];
int b[105];
int c[105];
int main()
{
int n,k;
cin>>n>>k;
for(int t=1;t<=n;t++)
{
scanf("%d",&a[t]);
}
int sum1;
int sum2;
int maxn=0;
for(int t=1;t<=n;t++)
{
sum1=0;
sum2=0;
for(int j=1;j<=n;j++)
{
if((j-t)%k==0)
{
continue;
}
else if(a[j]==-1)
{
sum1++;
}
else
{
sum2++;
}
}
maxn=max(maxn,abs(sum1-sum2));
}
cout<<maxn<<endl;
return 0;
}
Codeforces Round #532 (Div. 2)- A(思维)的更多相关文章
- Codeforces Round #532 (Div. 2)
Codeforces Round #532 (Div. 2) A - Roman and Browser #include<bits/stdc++.h> #include<iostr ...
- Codeforces Round #532 (Div. 2) 题解
Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...
- Codeforces Round #532 (Div. 2)- B(思维)
Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #395 (Div. 2)(A.思维,B,水)
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理
https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
随机推荐
- dubbo+zookeeper+dubboadmin环境搭建
4.环境搭建 4.1.zookeeper注册中心的配置安装(在windows平台下,Linux类似,见官方文档)(Redis注册中心安装,简易注册中心安装,简易监控中心安装,见官方文档) 下载zook ...
- java中用正则表达式判断中文字符串中是否含有英文或者数字
public static boolean includingNUM(String str)throws Exception{ Pattern p = Pattern.compile(" ...
- C++面向对象类的实例题目四
题目描述: 以面向对象的概念设计一个类,此类包含3个私有数据:unlead.lead(无铅汽油和有铅汽油)以及total(当天总收入,无铅汽油的价格是17元/升,有铅汽油的加个是16元/升),请以构造 ...
- unity3d 5.6参考手册
http://www.vfkjsd.cn/unity3d/Manual/index.html http://www.vfkjsd.cn/unity/unity3d.html
- HDU 3974 Assign the task (DFS+线段树)
题意:给定一棵树的公司职员管理图,有两种操作, 第一种是 T x y,把 x 及员工都变成 y, 第二种是 C x 询问 x 当前的数. 析:先把该树用dfs遍历,形成一个序列,然后再用线段树进行维护 ...
- dojo1.7 加载器
原文地址:http://dojotoolkit.org/documentation/tutorials/1.7/modules/ dojo现在支持在异步模块异步(AMD)定义中加入模块写入功能了,这使 ...
- [C# 线程处理系列]专题四:线程同步
目录: 一.线程同步概述 二.线程同步的使用 三 .总结 一.线程同步概述 前面的文章都是讲创建多线程来实现让我们能够更好的响应应用程序,然而当我们创建了多个线程时,就存在多个线程同时访问一个共享的资 ...
- 【转,整理】C# 非托管代码
.Net Framework 是由彼此独立又相关的两部分组成:CLR 和 类库, CLR是它为我们提供的服务,类库是它实现的功能..NET的大部分特性----垃圾收集,版本控制,线程管理等,都使用了C ...
- C# System.Timers.Timer定时器的使用和定时自动清理内存应用
项目比较大有时候会比较卡,虽然有GC自动清理机制,但是还是有不尽人意的地方.所以尝试在项目启动文件中,手动写了一个定时器,定时清理内存,加快项目运行速度. public class Program { ...
- Repeater控件的分隔线
在Repeater控件中,很容易实现在行与行之间使用分隔线.因为此控件有内置的SeparatorTemplate模版.举个例子吧: 运行时,可以看到效果: 说句实在的话,Insus.NET做一条水平线 ...