ChangChun_1001 A Simple Problem with Integers (HDU 4267)

解题报告什么的,都包含在Code里。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<string>
#include<map>
#define eps 1e-7
#define LL long long
#define N 500005
#define zero(a) fabs(a)<eps
#define lson step<<1
#define rson step<<1|1
#define MOD 1234567891
#define pb(a) push_back(a)
using namespace std;
struct Node{
    int left,right,add[55],sum;
    int mid(){return (left+right)/2;}
}L[4*N];
int a[N],n,b[11][11];

//此题很容易想到线段树,关键怎么把离散的点,整成连续的段。
//K很小是个突破口,如果坚持用线段树的话,就要去想怎么样把这么离散的点,化作段更新,因为多个点更新对于线段树是不利的。

void Bulid(int step ,int l,int r){
    L[step].left=l;
    L[step].right=r;
    L[step].sum=0;
    memset(L[step].add,0,sizeof(L[step].add));
    if(l==r) return ;
    Bulid(lson,l,L[step].mid());
    Bulid(rson,L[step].mid()+1,r);
}
void push_down(int step){ //把线段的sum值与add值传到线段内每个点。
    if(L[step].sum){
        L[lson].sum+=L[step].sum;
        L[rson].sum+=L[step].sum;
        L[step].sum=0;
        for(int i=0;i<55;i++){
                L[lson].add[i]+=L[step].add[i];
                L[rson].add[i]+=L[step].add[i];
                L[step].add[i]=0;
        }
    }
}
void update(int step,int l,int r,int num,int i,int j){ // i==d, j==l%d
    if(L[step].left==l && L[step].right==r){
        L[step].sum+=num;
        L[step].add[b[i][j]]+=num;
        return;
    }
    push_down(step);
    if(r<=L[step].mid()) update(lson,l,r,num,i,j);
    else if(l>L[step].mid()) update(rson,l,r,num,i,j);
    else {
        update(lson,l,L[step].mid(),num,i,j);
        update(rson,L[step].mid()+1,r,num,i,j);
    }
}
int query(int step,int pos){
    if(L[step].left==L[step].right){
        int tmp=0;
        for(int i=1;i<=10;i++)  tmp+=L[step].add[b[i][pos%i]]; // 这一点 %d (1<=d<=10) 能取到的值 的对应add值的和。
        return a[L[step].left]+tmp;
    }
    push_down(step);
    if(pos<=L[step].mid()) return query(lson,pos);
    else return query(rson,pos);
}
int main(){
    int cnt=0;
    for(int i=1;i<=10;i++) for(int j=0;j<i;j++) {
		b[i][j]=cnt++;
		printf("%d%c",b[i][j],j==i-1?'\n':' '); // 打表
	}
    while(scanf("%d",&n)!=EOF){
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        Bulid(1,1,n);
        int q,d;
        scanf("%d",&q);
        while(q--){
            int k,l,r,m;
            scanf("%d",&k);
            if(k==2){
                scanf("%d",&m);
                printf("%d\n",query(1,m));
            }
            else{
                scanf("%d%d%d%d",&l,&r,&d,&m);
                update(1,l,r,m,d,l%d);
            }
        }
    }
    return 0;
}

/*

内存比较紧,要把所有的情况压缩一下,不能开10*10的空间,于是用b[i][j] 
表示 b[i][j] % i 后有 j 种取值情况,每种不同的 i , j 用数字区分开来,
总共就 55 种情况,打表后是这个样子:

0
1 2
3 4 5
6 7 8 9
10 11 12 13 14
15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 32 33 34 35
36 37 38 39 40 41 42 43 44
45 46 47 48 49 50 51 52 53 54

*/


 

在MATLAB中绘制长春市的地图,你需要首先获取相关的地图数据,通常包括地理坐标数据(经度和纬度)。如果你没有现成的数据,可以考虑使用一些在线资源提供的地理编码服务(如Google Maps API或Bing Maps API),将长春市的具体地点转换为经纬度。 以下是基本步骤: 1. **安装地图支持包**: 如果你还没有安装,需要安装`geobubble`或其他地图可视化工具包,如`mapdata`或`geoplot`. ```matlab % 如果没有安装,运行以下代码 if ~exist('geobubble', 'file') addpath(genpath(matlabroot+'/toolbox/map.toolbox')); end ``` 2. **获取地图数据**: 使用`geocode`函数从网上获取长春市的经纬度数据,例如长春市政府位置。 ```matlab changchun_location = geocode('Changchun Municipal Government'); [changchun_lat, changchun_lon] = deal(changchun_location.Latitude, changchun_location.Longitude); ``` 3. **加载中国地图数据**: 要显示特定区域的地图,MATLAB有一些预设的世界地图数据,也可以使用第三方数据集。使用`loadmap`加载中国的地图数据。 ```matlab load(mapdata.MapData); worldmap = usamap; ``` 4. **绘制地图**: 将获取到的长春市经纬度添加到地图上,并设置范围。 ```matlab figure bubble(map=worldmap, positions=[changchun_lon changchun_lat], radii=ones(size(changchun_lon)),... markerfacecolor='red', MarkerEdgeColor='black', hold on); geobubble([worldmap.Lon; changchun_lon], [worldmap.Lat; changchun_lat]); xlim([-180 180]) ylim([-90 90]) % 显示城市名称 text(changchun_lon(1), changchun_lat(1), 'Changchun City', 'HorizontalAlignment', 'center'); % 显示地图边界范围 lonlims = worldmap.XLim; latlims = worldmap.YLim; hold off ``` 这只是一个基础示例,实际操作中可能需要根据实际情况调整地图比例尺和详细程度。如果你无法获取实时经纬度数据,可以使用固定的城市点作为示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值