• LUXURY 8


    A - Gargari and Bishops
    Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.

    He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.

    We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).

    Input

    The first line contains a single integer n(2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij(0 ≤ aij ≤ 109) — description of the chessboard.

    Output

    On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2(1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to nfrom left to right.

    If there are several optimal solutions, you can print any of them.

    Sample Input

    Input
    4
    1 1 1 1
    2 1 1 0
    1 1 1 0
    1 0 0 1
    Output
    12
    2 2 3 2
     做这道题会碰到2个问题:
    1.如何很方便的得到每个“X”的值?经过yy可以发现矩阵上在"/"这种形状上i+j都为定值,而在""上i + n - j为定值,所以预处理出“" , "/"对应的数组,然后你就能在O(1)时间内得到每个”X"
    2.如何能很快的知道两个“X",符合题设的条件?多画几次你就会发现i+j为奇数,和偶数是,那两个叉肯定不会存在公共点。
    观察很重要啊
     
     
     
    B - Bits
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    Let's denote as  the number of bits set ('1' bits) in the binary representation of the non-negative integer x.

    You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and  is maximum possible. If there are multiple such numbers find the smallest of them.

    Input

    The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).

    Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).

    Output

    For each query print the answer in a separate line.

    Sample Input

    Input
    3
    1 2
    2 4
    1 10
    Output
    1
    3
    7

    Hint

    The binary representations of numbers from 1 to 10 are listed below:

    110 = 12

    210 = 102

    310 = 112

    410 = 1002

    510 = 1012

    610 = 1102

    710 = 1112

    810 = 10002

    910 = 10012

    1010 = 10102

    一个纯粹的贪心,可以按位一步一步贪。

    C - No to Palindromes!
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and sdoesn't contain any palindrome contiguous substring of length 2 or more.

    Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.

    Input

    The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).

    Output

    If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).

    Sample Input

    Input
    3 3
    cba
    Output
    NO
    Input
    3 4
    cba
    Output
    cbd
    Input
    4 4
    abcd
    Output
    abda

    Hint

    String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti,si + 1 > ti + 1.

    The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.

    A palindrome is a string that reads the same forward or reversed.

    一道构造题,构造题真是。。。。。

    要做这道题,有个结论非常重要,那就是只有“部分对称” , 才会有可能性造成“整体堆成”,所以只要破坏所有“部分对称“,就行了。

    而部分对称只有两种形式”aa” , “aba”

     
     
    D - George and Job
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.

    Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers:

    [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 < l2 ≤ r2 < ... < lk ≤ rk ≤ nri - li + 1 = m), 

    in such a way that the value of sum  is maximal possible. Help George to cope with the task.

    Input

    The first line contains three integers nm and k(1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn(0 ≤ pi ≤ 109).

    Output

    Print an integer in a single line — the maximum possible value of sum.

    Sample Input

    Input
    5 2 1
    1 2 3 4 5
    Output
    9
    Input
    7 1 3
    2 10 7 18 5 33 0
    Output
    61
     一道裸的dp,一开始需要转移的状态没有想清楚,然后学长提醒后,很快就想到了,我用dp[前i个人][j个组] = max (当前i为第j组的最后一人 ,dp[i-1][j])
    转移的状态真心要想清楚啊。
     
  • 相关阅读:
    测试工具PerfDog的使用
    1.人工智能解读与Python简介
    如何提高百度网盘下载速度小技巧(亲测有效!)
    学习方法
    字符串换行工具类/每隔几位插入指定字符串
    java对pdf文件加文字水印 itextpdf
    centos 7.6 安装jdk8
    1 elk软件的安装
    Springboot 2.2.1 与activeMq 集成2 topic 发布者,订阅者
    Springboot 2.2.1 与activeMq 集成2 queue 消息
  • 原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4693008.html
Copyright © 2020-2023  润新知