0pts求助
  • 板块学术版
  • 楼主zyc1219
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/1/13 11:59
  • 上次更新2023/10/24 04:27:56
查看原帖
0pts求助
748426
zyc1219楼主2023/1/13 11:59

U236690

#include<bits/stdc++.h>
using namespace std;
int t,x,l[105],r[105],ans,j,maxx;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>t>>x;
	if(t=1){
		cin>>l[1]>>r[1];
		if(l[1]!=1){
			l[1]=l[1]-l[1]%x;
			cout<<r[1]-l[1]<<endl;
		}else{
			cout<<r[1]<<endl;
		}
	}
	for(int i=1;i<=t;i++){
		cin>>l[i]>>r[i];
		maxx=max(maxx,r[i]);
	}
	for(int i=0;i<maxx; ){
		if(i+x<l[j]){
			l[j]+=x;
		}if(i+x==l[j]){
			ans+=r[j]-l[j];
			i=r[j];
			j++;
		}if(i+x>l[j]){
			ans+=r[j]-i;
			i=r[j];
			j++;
		}
	}
	cout<<ans<<endl;
    return 0;
}
2023/1/13 11:59
加载中...