zoukankan
html css js c++ java
HDU3461 Code Lock 并查集应用
/* 这题程序不难,关键想法比较难,以下内容来自别人的空间 如果没有区间存在,答案是26^n,每增加一个区间,n-1(因为这个区间可以变成26种状态~). 但是要注意的是,比如已经有(1,10)和(1,3)在了,此时再增加(4,10)就没有作用了 使用并查集对于[l,r]我们将l,r+1两个点并起,如果新线段的两个点是同一个集合,就不用减了 */ #include <iostream> #include "UFS.h" #include <cmath> using namespace std; int mod = 1000000007; int exp(int a, int n); UFS ufs; int main() { int n,m, ans; while(cin>>n>>m) { ans = n; ufs.clear(); while(m--) { int a,b; cin>>a>>b; if(ufs.Find(a) != ufs.Find(b+1)) { ufs.Union(a, b+1); ans--; } } cout<<exp(26, ans)<<endl; } return 0; } //非递归求幂 int exp(int a, int n) { __int64 temp1 = 1, temp2 = a; while(n) { if(n & 1) temp1 =( temp1 * temp2 ) % mod; n>>=1; temp2 =( temp2 * temp2 ) % mod; } return temp1; }
查看全文
相关阅读:
手机浏览器
一招封住360流氓
原来在Delphi中的类型是严格匹配的
Windows 7下面3389远程连接时“超出最大连接数”解决办法
大家开发过淘宝商城API应用的么?
adodb.recordset 添加记录后无法取得ID
VBATrack Picture
java web后台开发SSM框架(Spring+SpringMVC+MyBaitis)搭建与优化
VBATrack MsgBox
VBATrack 暂停3秒运行
原文地址:https://www.cnblogs.com/windmissing/p/2559863.html
最新文章
大三上课程总结
寒假进度5IDEA的安装与使用
寒假进度1PyTorch环境配置与安装
命令设置ip,dns,网关
linux下的两级路由
form 阻止提交
context的一个常用设置
又回到了arch
有关于支付宝的控件与lamp的设置
路由相关
热门文章
beautifulsoup
beautifulsoup sae
pdf2htmlIEX
pppoe route
vim IDE 进一步
linuxer的windows生存手册
jquery 小点
thinkphp sae
xhr 加载顺序
thinkphp 又一问题
Copyright © 2011-2022 走看看