【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
2016-08-30 15:57
543 查看
题目链接:
http://codeforces.com/gym/100851
题目大意:
一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和。C c取出第c列还未被取出的所有数并输出和。
题目思路:
【模拟】
首先Ai,j=i+j这个很关键。预处理每一行(=列)的值。
只要记录当前取得时候前面已经取过的所有行数的和、次数,所有列数的和、次数,就能推算出这次取数会少掉多少值。
并记录这一行或这一列被取过没有。
View Code
http://codeforces.com/gym/100851
题目大意:
一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和。C c取出第c列还未被取出的所有数并输出和。
题目思路:
【模拟】
首先Ai,j=i+j这个很关键。预处理每一行(=列)的值。
只要记录当前取得时候前面已经取过的所有行数的和、次数,所有列数的和、次数,就能推算出这次取数会少掉多少值。
并记录这一行或这一列被取过没有。
// //by coolxxx //#include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<string> #include<iomanip> #include<map> #include<stack> #include<queue> #include<set> #include<bitset> #include<memory.h> #include<time.h> #include<stdio.h> #include<stdlib.h> #include<string.h> //#include<stdbool.h> #include<math.h> #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abs(a) ((a)>0?(a):(-(a))) #define lowbit(a) (a&(-a)) #define sqr(a) ((a)*(a)) #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b)) #define mem(a,b) memset(a,b,sizeof(a)) #define eps (1e-8) #define J 10 #define mod 1000000007 #define MAX 0x7f7f7f7f #define PI 3.14159265358979323 #define N 1000004 using namespace std; typedef long long LL; int cas,cass; int n,m,lll,ans; LL sum,tot,a,b; LL c ; char s[2]; bool u ,v ; int main() { #ifndef ONLINE_JUDGE // freopen("3.txt","r",stdin); // freopen("2.txt","w",stdout); #endif int i,j,k; // for(scanf("%d",&cass);cass;cass--) // for(scanf("%d",&cas),cass=1;cass<=cas;cass++) // while(~scanf("%s",s+1)) while(~scanf("%d",&n)) { sum=tot=a=b=0;mem(u,0);mem(v,0); scanf("%d",&m); c[1]=1LL*(2+1+n)*n/2; for(i=2;i<=n;i++)c[i]=c[i-1]+n; for(i=1;i<=m;i++) { scanf("%s%d",s,&cas); if(s[0]=='R') { if(u[cas]){puts("0");continue;} printf("%I64d\n",c[cas]-tot-b*cas); sum+=cas; a++; u[cas]=1; } else { if(v[cas]){puts("0");continue;} printf("%I64d\n",c[cas]-sum-a*cas); tot+=cas; b++; v[cas]=1; } } } return 0; } /* // // */
View Code
相关文章推荐
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 【二分】NEERC15 L Landscape Improved(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 【最短路】NEERC15 F Froggy Ford(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 【模拟】NEERC15 A Adjustment Office (Codeforces GYM 100851)
- Codeforces GYM 100548 F - Color 2014-2015 ACM-ICPC, Asia Xian Regional Contest
- Codeforce Gym 100819P : 2015-2016 ACM-ICPC Pacific Northwest Regional Contest - P 仔细看题啊!
- 【模拟】NEERC15 G Generators (Codeforces GYM 100851)
- Codeforces GYM 100548 K - Last Defence 2014-2015 ACM-ICPC, Asia Xian Regional Contest
- Codeforce Gym 100819L : 2015-2016 ACM-ICPC Pacific Northwest Regional Contest - L 这是一道阅读理解(微笑)
- 【模拟】NEERC15 E Easy Problemset (Codeforces GYM 100851)
- 【模拟】NEERC15 J Jump (Codeforces GYM 100851)
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases(模拟STL vector+map)
- Codeforces Gym 101190 (NEERC 2016) H. Hard Refactoring (模拟 + 树状数组)
- 【二分】NEERC15 L Landscape Improved (Codeforces GYM 100851)
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest D】【模拟 讨论】Boulevard 人流行走看是否相交 beautiful code
- codeforces Gym - 101485 D Debugging (2015-2016 Northwestern European Regional Contest (NWERC 2015))