zoukankan      html  css  js  c++  java
  • D. Walk on Matrixv

    D. Walk on Matrix
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Bob is playing a game named "Walk on Matrix".

    In this game, player is given an n×mn×m matrix A=(ai,j)A=(ai,j), i.e. the element in the ii-th row in the jj-th column is ai,jai,j. Initially, player is located at position (1,1)(1,1) with score a1,1a1,1.

    To reach the goal, position (n,m)(n,m), player can move right or down, i.e. move from (x,y)(x,y) to (x,y+1)(x,y+1) or (x+1,y)(x+1,y), as long as player is still on the matrix.

    However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.

    Bob can't wait to find out the maximum score he can get using the tool he recently learnt  — dynamic programming. Here is his algorithm for this problem.

    However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix AA. Thus, for any given non-negative integer kk, he wants to find out an n×mn×m matrix A=(ai,j)A=(ai,j) such that

    • 1n,m5001≤n,m≤500 (as Bob hates large matrix);
    • 0ai,j31050≤ai,j≤3⋅105 for all 1in,1jm1≤i≤n,1≤j≤m (as Bob hates large numbers);
    • the difference between the maximum score he can get and the output of his algorithm is exactly kk.

    It can be shown that for any given integer kk such that 0k1050≤k≤105, there exists a matrix satisfying the above constraints.

    Please help him with it!

    Input

    The only line of the input contains one single integer kk (0k1050≤k≤105).

    Output

    Output two integers nn, mm (1n,m5001≤n,m≤500) in the first line, representing the size of the matrix.

    Then output nn lines with mm integers in each line, ai,jai,j in the (i+1)(i+1)-th row, jj-th column.

    Examples
    input
    Copy
    0
    
    output
    Copy
    1 1
    300000
    input
    Copy
    1
    
    output
    Copy
    3 4
    7 3 3 1
    4 8 3 6
    7 7 7 3
    Note

    In the first example, the maximum score Bob can achieve is 300000300000, while the output of his algorithm is 300000300000.

    In the second example, the maximum score Bob can achieve is 7&3&3&3&7&3=37&3&3&3&7&3=3, while the output of his algorithm is 22.

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll  long long
    #define PII  pair<int, int>
    using namespace std;
    int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979;
    const int mod = 1e9 + 7;
    const int maxn = 2005;
    //if(x<0 || x>=r || y<0 || y>=c)
    //1000000000000000000
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    int k;
    int Add;
    int a[5][5];
    map<int, bool>vis;
    
    int main() {
        k=read();
        if (k == 0) {
            printf("1 1
    ");
            printf("23333");
        }
        else {
            printf("2 3
    ");
            int Num = 1;
            for (int cnt = 0; cnt <= 17; cnt++) {
                vis[Num] = true;
                if (Num >= k) break;
                Num *= 2;
            }
            if (vis[k] == true) Num *= 2;
            a[1][1] = Num * 2 - 1;
            a[1][2] = k;
            a[1][3] = 0;
            a[2][1] = Num;
            a[2][2] = Num * 2 - 1;
            a[2][3] = k;
            for (int i = 1; i <= 2; i++) {
                for (int j = 1; j <= 3; j++) {
                    printf("%d ", a[i][j]);
                }
                puts("");
            }
        }
        return 0;
    }
     
  • 相关阅读:
    Java 线程间通信 —— 等待 / 通知机制
    Java 线程基础
    Java 内存模型
    Java 并发机制底层实现 —— volatile 原理、synchronize 锁优化机制、原子操作
    优秀程序员的博客有哪些?
    程序员五一被拉去相亲,结果彻底搞懂了HTTP常用状态码
    【Redis破障之路】三:Redis单线程架构
    【Redis破障之路】一:强大的Redis
    MySQL提升笔记(4)InnoDB存储结构
    MySQL提升笔记(3)日志文件详解
  • 原文地址:https://www.cnblogs.com/dealer/p/12678233.html
Copyright © 2011-2022 走看看