• Gym 100851A Adjustment Office (思维)


    题意:给定一个 n*n 的矩阵,然后有 m 个询问,问你每一行或者每一列总是多少,并把这一行清空。

    析:这个题不仔细想想,还真不好想,我们可以根据这个题意,知道每一行或者每一列都可以求和公式来求,然后再送去变成0的数,由于每一行或者每一列,

    都是等差数列,所以我们只要记录每一个的第一个元素就好,再记录有多少个,然后就可以推算出来。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const LL LNF = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e6 + 5;
    const int mod = 1e9 + 7;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    char s[5];
    bool row[maxn], col[maxn];
    
    int main(){
        freopen("adjustment.in", "r", stdin);
        freopen("adjustment.out", "w", stdout);
        while(scanf("%d %d", &n, &m) == 2){
            memset(row, false, sizeof row);
            memset(col, false, sizeof col);
            int x = 0;
            LL r = 0, c = 0;
            int cntr = 0, cntc = 0;
            LL ans = 0;
            for(int i = 0; i < m; ++i){
                scanf("%s %d", s, &x);
                if(s[0] == 'R'){
                    if(row[x])  ans = 0;
                    else{
                        r += x;
                        ++cntr;
                        ans = (LL)n*(LL)(x+x+n+1)/2LL - (LL)cntc*x - c;
                    }
                    row[x] = true;
                }
                else {
                    if(col[x]) ans = 0;
                    else{
                        c += x;
                        ++cntc;
                        ans = (LL)n*(LL)(x+x+n+1)/2LL - (LL)cntr*x - r;
                    }
                    col[x] = true;
                }
                printf("%I64d
    ", ans);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    I2C总线的设计
    注意: Cyusb2.0插在PC上的端口
    BULKTranfer
    浅析值类型与引用类型的内存分配
    sql server2008用ip远程连接,解决默认连不上的问题
    Decimal 结构
    单例模式 需要用showdialog 如果用show需要做如下改动
    NET4.0新功能之String.IsNullOrWhiteSpace() 方法
    SQLserver2008打不开的问题
    (C#)Winform修改DateTimePicker控件的背景色
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5875458.html
Copyright © 2020-2023  润新知