zoukankan      html  css  js  c++  java
  • 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接:

      http://codeforces.com/gym/100851

    题目大意:

      一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和。C c取出第c列还未被取出的所有数并输出和。

    题目思路:

      【模拟】

      首先Ai,j=i+j这个很关键。预处理每一行(=列)的值。

      只要记录当前取得时候前面已经取过的所有行数的和、次数,所有列数的和、次数,就能推算出这次取数会少掉多少值。

      并记录这一行或这一列被取过没有。

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<stack>
    10 #include<queue>
    11 #include<set>
    12 #include<bitset>
    13 #include<memory.h>
    14 #include<time.h>
    15 #include<stdio.h>
    16 #include<stdlib.h>
    17 #include<string.h>
    18 //#include<stdbool.h>
    19 #include<math.h>
    20 #define min(a,b) ((a)<(b)?(a):(b))
    21 #define max(a,b) ((a)>(b)?(a):(b))
    22 #define abs(a) ((a)>0?(a):(-(a)))
    23 #define lowbit(a) (a&(-a))
    24 #define sqr(a) ((a)*(a))
    25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    26 #define mem(a,b) memset(a,b,sizeof(a))
    27 #define eps (1e-8)
    28 #define J 10
    29 #define mod 1000000007
    30 #define MAX 0x7f7f7f7f
    31 #define PI 3.14159265358979323
    32 #define N 1000004
    33 using namespace std;
    34 typedef long long LL;
    35 int cas,cass;
    36 int n,m,lll,ans;
    37 LL sum,tot,a,b;
    38 LL c[N];
    39 char s[2];
    40 bool u[N],v[N];
    41 int main()
    42 {
    43     #ifndef ONLINE_JUDGE
    44 //    freopen("3.txt","r",stdin);
    45 //    freopen("2.txt","w",stdout);
    46     #endif
    47     int i,j,k;
    48 //    for(scanf("%d",&cass);cass;cass--)
    49 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    50 //    while(~scanf("%s",s+1))
    51     while(~scanf("%d",&n))
    52     {
    53         sum=tot=a=b=0;mem(u,0);mem(v,0);
    54         scanf("%d",&m);
    55         c[1]=1LL*(2+1+n)*n/2;
    56         for(i=2;i<=n;i++)c[i]=c[i-1]+n;
    57         for(i=1;i<=m;i++)
    58         {
    59             scanf("%s%d",s,&cas);
    60             if(s[0]=='R')
    61             {
    62                 if(u[cas]){puts("0");continue;}
    63                 printf("%I64d
    ",c[cas]-tot-b*cas);
    64                 sum+=cas;
    65                 a++;
    66                 u[cas]=1;
    67             }
    68             else
    69             {
    70                 if(v[cas]){puts("0");continue;}
    71                 printf("%I64d
    ",c[cas]-sum-a*cas);
    72                 tot+=cas;
    73                 b++;
    74                 v[cas]=1;
    75             }
    76         }
    77     }
    78     return 0;
    79 }
    80 /*
    81 //
    82 
    83 //
    84 */
    View Code
  • 相关阅读:
    Mac下安装svn服务器
    php 当前日期加一天和指定日期加一天
    MariaDB与MySQL
    JS中判断null、undefined与NaN的方法
    PHP保留两位小数的几种方法
    jquery的cookie插件
    mysql(5.7以上)查询报错:ORDER BY clause is not in GROUP BY..this is incompatible with sql_mode=only_full_group_by
    MySQL数据的导出和导入
    qrCode二维码字符串长度太多压缩的问题
    解决 img 标签上下出现的间隙
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5822380.html
Copyright © 2011-2022 走看看