Roman and Browser-罗曼的浏览器 CodeForce1100A 暴力

题目链接:Roman and Browser

题目原文

  This morning, Roman woke up and opened the browser with 𝑛 opened tabs numbered from 1 to 𝑛. 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 𝑘-th (2𝑘𝑛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 𝑏b) and then close all tabs with numbers 𝑐=𝑏+𝑖𝑘 that satisfy the following condition: 1𝑐𝑛1≤c≤n and 𝑖s an integer (it may be positive, negative or zero).

  For example, if 𝑘=3𝑛=14 and Roman chooses 𝑏=8, then he will close tabs with numbers 2,  5, 8, 11 and 14.

  After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it 𝑒) and the amount of remaining social network tabs (𝑠). Help Roman to calculate the maximal absolute value of the difference of those values |𝑒𝑠| so that it would be easy to decide what to do next.

题目大意

浏览器有标号为1-n的n个两种标签页,选择其中的一个标签页,以间隔b(b是不确定的)等间隔的关闭相应的标签页。求最后两种标签页数量的差值。

思路

按照公式𝑐=𝑏+𝑖𝑘,删除所有位置为c的元素,求剩余元素的绝对值的最大值。数据范围很小,暴力过一遍就行。

题解

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 using namespace std;
 5 
 6 int n, k, ans;
 7 int a[105];
 8 
 9 int main(int argc, char const *argv[])
10 {
11     cin >> n >> k;
12     int tmp = 0;
13     for (int i = 0; i < n; i++)
14     {
15         cin >> a[i];
16     }
17     for (int b = 0; b < k; b++)
18     {
19         tmp = 0;
20         for (int i = 0; i < n; ++i)
21         {
22             if ( i-b>=0 && (i-b) % k == 0)
23             {
24                 
25             }else{
26                 tmp += a[i];
27             }
28         }
29         if (tmp < 0)
30         {
31             tmp = -tmp;
32         }
33         if(tmp > ans)
34         {
35             ans = tmp;
36         }
37     }
38 
39     cout << ans;
40     return 0;
41 }

 

posted @ 2019-02-17 21:48  SaltyFishQF  阅读(217)  评论(0编辑  收藏  举报