Codeforces-835C

题目大意:天空上有n颗星星,每颗星星都有其自己的坐标(x,y)和初始发光值s,对于所有星星都有共同的最大的发光值c。

                    现在给出q段询问,分别给出时刻t,矩形的左下角坐标(x1,y1),右上角坐标(x2,y2),求在t时刻后该矩形内所能看

                     的发光值总和。

                    发光值计算方法:对于T时刻某一星星有发光值s1,在T+1时刻时,如果s1+1<=c,则发光值为s1+1,否则为0,

                    依次循环递推。

                    在矩形内或矩形边界上的星星都算在所求的总和内。

                    

题目分析:一开始做得时候没有考虑到可以有多个星星有共同的坐标..WA掉了,比赛完后看讨论知道后再改发现暴力写法T了.....

                     后来参考官方题解发现竟然是道DP题....orz.....

                    状态转移方程的话是C[p][x][y]+=C[p][x][y-1]+C[p][x-1][y]-C[p][x-1][y-1],其中p是发光值,计算完后C[p][x][y]保持得是其左下方

                    这一块矩形的发光值为p的星星总数。

                    后来计算得时候同样是查询矩形块内各发光值的星星总数,然后进行相应的相乘得解(可以简单的画个坐标系理解一下)

  

#include<iostream>
#include<cmath>
#include<cstdio>
#include<map>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
int ax[11][105][105],vis[105][105];
int main()
{
    int n,q,c,sum=0;
    scanf("%d%d%d",&n,&q,&c);
    memset(ax,0,sizeof(ax));
    for(int i=0;i<n;i++)
    {
        int x,y,ans;
        scanf("%d%d%d",&x,&y,&ans);
        ax[ans][x][y]++;
    }
    for(int i=0;i<=c;i++)
        for(int x=1;x<=100;x++)
           for(int y=1;y<=100;y++)
      ax[i][x][y]+=ax[i][x-1][y]+ax[i][x][y-1]-ax[i][x-1][y-1];

    while(q--)
    {
      sum=0;
      int t,x1,y1,x2,y2;
      scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
      for(int i=0;i<=c;i++)
      {

          sum+=(ax[i][x2][y2]-ax[i][x1-1][y2]-ax[i][x2][y1-1]+ax[i][x1-1][y1-1])*((i+t)%(c+1));
      }
      printf("%d\n",sum);
    }
   return 0;
}


### Codeforces Problem 976C Solution in Python For solving problem 976C on Codeforces using Python, efficiency becomes a critical factor due to strict time limits aimed at distinguishing between efficient and less efficient solutions[^1]. Given these constraints, it is advisable to focus on optimizing algorithms and choosing appropriate data structures. The provided code snippet offers insight into handling string manipulation problems efficiently by customizing comparison logic for sorting elements based on specific criteria[^2]. However, for addressing problem 976C specifically, which involves determining the winner ('A' or 'B') based on frequency counts within given inputs, one can adapt similar principles of optimization but tailored towards counting occurrences directly as shown below: ```python from collections import Counter def determine_winner(): for _ in range(int(input())): count_map = Counter(input().strip()) result = "A" if count_map['A'] > count_map['B'] else "B" print(result) determine_winner() ``` This approach leverages `Counter` from Python’s built-in `collections` module to quickly tally up instances of 'A' versus 'B'. By iterating over multiple test cases through a loop defined by user input, this method ensures that comparisons are made accurately while maintaining performance standards required under tight computational resources[^3]. To further enhance execution speed when working with Python, consider submitting codes via platforms like PyPy instead of traditional interpreters whenever possible since they offer better runtime efficiencies especially important during competitive programming contests where milliseconds matter significantly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值