跳到正文

_yhb_

1986324

花有重开日,人无再少年

在洛谷打开
资料、奖项与版本

资料

编号
1986324
抓取

陶片放逐

+ 发送私信
− 发送私信

查看记录

C++
#include <bits/stdc++.h>
using namespace std;
long long n;
double x;
long long hang,lie;//行与列 
long long a,b;
int main()
{
	while(~scanf("%lld",&n))//读入数据 
	{
		x=1.0*(sqrt(1+8*n)-1)/2;//求行数 
		hang=x;
		if(double(hang)!=x) hang+=1;
		lie=n-hang*(hang-1)/2;//求列数 
		a=hang-lie+1;b=lie;//规律 
		printf("%lld/%lld\n",a,b);
	}
	return 0;
}



#include<bits/stdc++.h>
#define ll long long
#define inf 1e9+10
using namespace std;
const int maxn=1e5+10;
struct mxr{
 	int to,next,val;
}e[2*maxn];
int n,cnt,m,vis[maxn],head[maxn],s;
int dis[maxn];
priority_queue<pair<ll,int> >q;
inline void add(int u,int v,int w)
{
 e[cnt].to=v;
 e[cnt].val=w;
 e[cnt].next=head[u];
 head[u]=cnt++;
 return ;
}
inline void dij()
{
 	q.push(make_pair(0,s));
 	dis[s]=0;
 	while(!q.empty()) {
     	int now=q.top().second;
     	q.pop();
     	if(vis[now]) continue;
     	vis[now]=1;
     	for(int i=head[now];i!=-1;i=e[i].next){
         	int v=e[i].to;
         	if(dis[v]>dis[now]+e[i].val){
             	dis[v]=dis[now]+e[i].val;
             	q.push(make_pair(-dis[v],v));
        }
    }
 }
 return ;
}
int main(){
	memset(head,-1,sizeof(head));
 	cnt=0;
    cin>>n>>m>>s;
    for(int i=1;i<=n;i++) dis[i]=inf;
 	for(int i=1;i<=m;i++){
     	int a,b,w;
        cin>>a>>b>>w;
     	add(a,b,w);
 	}
 	dij();
 	for(int i=1;i<=n;i++) printf("%d ",dis[i]);
 	return 0;
}

分块

C++
#include<bits/stdc++.h>
using namespace std;
int a[500005],id[500005],num[1000],l[1000],r[1000],len,nm;
int fd(int x,int y){
	int id1=id[x],id2=id[y],ans=0; 
	if(id1==id2){
		for(int i=x;i<=y;i++){
			ans+=a[i];
		} 
	}
	else{
		for(int i=x;i<=r[id[x]];i++) ans+=a[i];
		for(int i=id[x]+1;i<=id[y]-1;i++)ans+=num[i];
		for(int i=l[id[y]];i<=y;i++) ans+=a[i];
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); 
	int n,m;
	cin>>n>>m;
	len=sqrt(n),nm=((n+len-1)/len);
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
		id[i]=(i-1)/len+1;
	for(int i=1;i<=nm;i++){
		l[i]=len*(i-1)+1;
		r[i]=min(i*len,n);
	}
	for(int i=1;i<=n;i++)
		num[id[i]]+=a[i];
	while(m--){
		int o,x,y;
		cin>>o>>x>>y;
		if(o==1){
			num[id[x]]+=y;
			a[x]+=y;
		}
		else {
			cout<<fd(x,y)<<'\n';
		}
//		for(int i=1;i<=n;i++){
//			cout<<a[i]<<' ';
//		}cout<<'\n';
	}
	return 0;
}
代码
         新域名推荐网                    
         版本号:_?.??

----------------

新域名推荐网是一个用于推荐网址的网站,作为一个普通人或是一个作企业宣布的人很有帮助,你可以将感兴趣的网址推荐到这里。

####这只是一次简单的补丁而已,请您不要在意

以下为markdown运行形式,请勿删除

↡点击下方按钮可切换颜色

[ ? ](javascript: s=document.createElement(style); s.textContent= :root吗{--tech-blue:#409cff;--tech-darkblue:#202040;--tech-shadow:rgba(64,156,255,0.1);--tech-blue-hover:#64b4ff;--tech-shadow-hover:rgba(32,31,64,0.25);--tech-darkblue-hover:#303999}h1,h2,h3,h4,h5,h6{font-weight:600;color:var(--tech-blue);line-height:1.3;letter-spacing:0.5px;margin:24px0;width:fit-content;padding-bottom:12px}hr{border:none;height:2px;border-radius:999px;background:var(--tech-darkblue-hover)}a{position:relative;text-decoration:none;display:inline-block;color:var(--tech-blue)!important;}a:hover{color:var(--tech-darkblue-hover)!important}.flag{visibility:hidden}::-webkit-scrollbar{width:5px;height:10px}::-webkit-scrollbar-track{background:#1111ff;border-radius:100px}::-webkit-scrollbar-thumb{border-radius:100px;background:var(--tech-blue)}html{background:#1111ff33!important}.content{background:#915cd311!important}; document.head.appendChild(s); )

↺[在?????://????.??/????.??观赏更佳]

本网站各区域的作用:

⒈实用区 用于分享你喜欢的网站网址

‖⒉游戏区 用于分享你喜欢的单个游戏网页网站

‖⒊NOTE组织区 对note部分组织进行收录(注:该区域的域名在普遍状态下直接写裸域名‌,若单个域名独立的情况下请写URL)

‖⒋其它区 除上述所述以外的其它网站类型进行分享
__________________

?️实用区:

宣团

千亿像素看中国

小霸王

毒鸡汤生成器

有趣网址之家

IT天空

Poki

SCPwiki

后室中文维基

后室mc层群维基

后室韩文维基

getnote

Minecraft官方网站

steam

Fontiner

蜜蜂图床

?游戏区:

hamenos

YORG.lO

maxwellcat

digdig!

florr

?NOTE组织区:

共产者联合计划
共产者联合计划总部 共产者联合计划分计划(note.ms/zhude,note.ms/Save)

布栏组织 布栏总部

NOTE反攻击联合同盟
NOTE反攻击联合同盟页面 《NOTE反攻击联合同盟宪章》

EVAS组织
EVAS组织页面(note.ms/next,note.ms/with,note.ms/from,note.ms/self,note.ms/full,note.ms/pick,note.ms/more,note.ms/Evas,note.ms/neck,note.ms/head,note.ms/body)

极星崩坏 极星崩坏页面 (note.ms/turningbage,note.ms/forum,note.ms/shuttacode,note.ms/shuttaexchange,note.ms/rdfzhiscp,note.ms/zhongguoniiubi,note.ms/storm)

notemsDC DC总站 notemsDC组织分站(note.ms/DC,note.ms/fuckDC,note.ms/dc,note.ms/Mianyang,note.ms/SichuanMianyang,note.ms/MianyangDC,note.ms/SichuanMianyangDC,note.ms/potato,note.ms/potatoDC,note.ms/potatoDongcheng,note.ms/potatodc,note.ms/dcpotato,note.ms/DCpotato,note.ms/Dongchengpotato)

联合与安全组织
联合与安全组织宣传页面
(note.ms/Japen,note.ms/Japenese)

薯片组织
薯片组织宣传页面

?其它区:

旋转老鼠

iuiuiu

fancytext.cool

共 1 篇
  1. 题解

    题解:B4211 [常州市赛 2022] 可能的三角形

    该题目要求根据输入的4个数(每个数必为三角形的边或边的和)找出所有可能的合法三角形三边组合。合法条件为:2≤A≤B≤C且满足三角形不等式A+B>C。解题思路如下: 关键观察:输入的4个数中至少包含一个和值(A+B、A+C、B+C或A+B+C),因为若全是边则无法组成4个数。因此需枚举所有可能的和值组合情况。 具体做法: 先对输入的4个数排序(x1≤x2≤x3≤x4)。 通过35种预设条件判断,分别假设不同数为和值,反推出可能的A、B、C组合。例如: 若x4是A+B,则C为x3,A和B为x1和x2。 若x3是A+B,则C可能为x4-x1、x4-x2或x4-x1-x2。 每次反推后,需验证A≥2且A+B>C,并确保A≤B≤C的顺序。 处理结果: 将所有符合条件的组合收集后,按A升序、B升序、C升序排序,并去除重复项。 代码逻辑: 使用结构体存储结果,通过排序和条件判断生成候选解。 最终输出前需进行去重,确保相同解不重复出现。 注意事项: 输入排序是前提,避免遗漏A≥2的条件。 35种情况需覆盖所有可能的和值组合,且需正确处理反推逻辑。 输出顺序必须严格遵循A、B、C的升序规则,需自定义比较函数实现。 整体复杂度为O(1),因枚举分支固定且最终答案数量极少。