喵哈哈村的魔法考试 Round #19 (Div.2) 题解
题解:
喵哈哈村的魔力源泉(1)
题解:签到题。
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c;
while(cin>>a>>b>>c){
cout<<a*b%c<<endl;
}
}
喵哈哈村的魔力源泉(2)
题解:首先快速幂是来处理次方的问题,那么我们模仿快速幂,写一个快速加即可,这样我们每次乘以2,就不会爆longlong了
代码:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
long long a,b,p;
long long ksj(long long a,long long b)
{
if(b==0)return 0;
if(b==1)return a%p;
long long sb=ksj(a,b/2);
sb=(sb+sb)%p;
if(b&1)
return (sb+a)%p;
else
return sb;
}
void read_in()
{
while(scanf("%lld%lld%lld",&a,&b,&p)!=EOF){
cout<<ksj(a,b)<<endl;
}
}
int main()
{
read_in();
return 0;
}
喵哈哈村的魔法源泉(3)
题解:答案实际上就是树的直径的一半,关于树的直径,这个自己百度吧~
代码:
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=200050;
vector<int> son[maxn],w[maxn];
bool vis[maxn];
int f[maxn];
int bfs(int root)
{
int i,j,k;
int ans=root,maxx=0;
queue<int> q;
memset(vis,0,sizeof(vis));
memset(f,0,sizeof(f));
q.push(root);
vis[root]=1;f[root]=0;
while(!q.empty())
{
root=q.front();
q.pop();
for(i=0;i<son[root].size();i++)//À©Õ¹Â·¾¶
{
if(vis[son[root][i]]==0)//È¥ÖØ
{
q.push(son[root][i]);
vis[son[root][i]]=1;
f[son[root][i]]=f[root]+w[root][i];
if(maxx<f[son[root][i]])
{
maxx=f[son[root][i]];
ans=son[root][i];//ansÊÇĿǰ¾àÀëROOT×îÔ¶µÄ½Úµã¡£
}
}
}
}
return ans;
}
int solve(int root)
{
int u,v;
u=bfs(root);
v=bfs(u);
return f[v];
}
int main()
{
int i,j,k,n,m;
int x1,x2,l,u;
scanf("%d",&n);
for(i=0;i<n;i++)
{
son[i].clear();
w[i].clear();
}
for(i=0;i<n-1;i++)
{
scanf("%d%d%d",&x1,&x2,&l);
son[x1].push_back(x2);w[x1].push_back(l);
son[x2].push_back(x1);w[x2].push_back(l);
}
double ans=solve(1)/2.0;
printf("%0.1f\n",ans);
return 0;
}
喵哈哈村的魔力源泉(4)
题解:单调队列优化的dp,这儿有个链接比我讲得清楚。。。
http://blog.csdn.net/oiljt12138/article/details/51174560
代码:
#include<iostream>
#include<cstdio>
using namespace std;
struct node
{
long long s;
int n;
}q[1000010];
int a,n,m;
long long s[1000010],ans;
int h,t;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
s[i]=a+s[i-1];
}
q[0].s=0;q[0].n=0;
for(int i=1;i<=n;i++)
{
long long r=s[i];
r-=q[t].s;
ans=max(ans,r);
while(t<=h&&q[h].s>s[i])h--;
q[++h].s=s[i];
q[h].n=i;
while(q[t].n<=i-m)t++;
}
cout<<ans;
return 0;
}
喵哈哈村的魔力源泉(5)
题解:类似two pointer去做,维护最小边,然后去枚举最大边。用带权并查集去维护每个集合的边的信息,如果所有点都大于等于了k,那么就输出答案即可。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#define maxlongint 2147483647
#define pb push_back
#define mp make_pair
#define LL long long
using namespace std;
struct dwell
{
int a,b;
LL w;
} key[5010];
struct bz
{
int where,cnt;
} fa[1010];
LL like[1010];
LL k;
int n,m;
bool cmp(dwell A,dwell B)
{
return A.w<B.w;
}
int Findset(int x)
{
if(fa[x].where==x)return x;else return Findset(fa[x].where);
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)scanf("%I64d",&like[i]);
for(int i=1;i<=m;i++)
scanf("%d%d%I64d",&key[i].a,&key[i].b,&key[i].w);
sort(key+1,key+m+1,cmp);
key[0].a=0;key[0].b=0;key[0].w=-100000000;
key[m+1].a=0;key[m+1].b=0;key[m+1].w=-100000000;
LL Minhz=-1,Maxhz=key[m].w+1,ans=0;
for(int i=1;i<=m;i++)
if(key[i].w!=key[i-1].w)
{
for(int j=1;j<=n;j++)
{
fa[j].where=j;
fa[j].cnt=1;
}
int j=i;
LL ans0=like[1]*n;
while(j<=m)
{
if(key[j].w-key[i].w>=Maxhz-Minhz)break;
int j0=j;
while(key[j0].w==key[j].w)j0++;
for(int x=j;x<j0;x++)
{
int s1=Findset(key[x].a),s2=Findset(key[x].b);
if(s1!=s2)
{
int X0=fa[s1].cnt,Y0=fa[s2].cnt;
ans0+=(like[X0+Y0]-like[X0]-like[Y0]);
fa[s1].cnt=X0+Y0;
fa[s2].cnt=X0+Y0;
if(s1>s2)fa[s1].where=s2;else fa[s2].where=s1;
if((ans0>=k)&&((Maxhz-Minhz>key[j].w-key[i].w)||(ans<k)))
{
ans=ans0;
Maxhz=key[j].w;
Minhz=key[i].w;
}
}
}
j=j0;
}
}
if(ans>=k)
printf("%lld\n",Maxhz-Minhz);
else
printf("T_T\n");
// system("pause");
return 0;
}
喵哈哈村的魔法考试 Round #19 (Div.2) 题解的更多相关文章
- 喵哈哈村的魔法考试 Round #2 (Div.2) 题解
喵哈哈村的魔法考试 Round #2 (Div.2) 题解 A.喵哈哈村的战争 题解: 这道题就是for一遍,统计每个村子的战斗力的和,然后统计哪个村子的战斗力和大一点就好了. 唯一的坑点,就是这道题 ...
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解
喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...
- 喵哈哈村的魔法考试 Round #7 (Div.2) 题解
喵哈哈村的魔法考试 Round #7 (Div.2) 注意!后四道题来自于周日的hihocoder offer收割赛第九场. 我建了个群:欢迎加入qscoj交流群,群号码:540667432 大概作为 ...
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解&源码(A.水+暴力,B.dp+栈)
A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05 最后更新: 2017年2月21日 20:06 时间限制: 1000ms 内存限制: 128M 描述 传说喵哈哈村有三种神 ...
- 喵哈哈村的魔法考试 Round #14 (Div.2) 题解
喵哈哈村的四月半活动(一) 题解: 唯一的case,就是两边长度一样的时候,第三边只有一种情况. #include <iostream> #include <cstdio> # ...
- 喵哈哈村的魔法考试 Round #4 (Div.2) 题解
有任何疑问,可以加我QQ:475517977进行讨论. A 喵哈哈村的嘟嘟熊魔法(1) 题解 这道题我们只要倒着来做就可以了,因为交换杯子是可逆的,我们倒着去模拟一遍就好了. 有个函数叫做swap(a ...
- 喵哈哈村的魔法考试 Round #20 (Div.2) 题解
题解: A 喵哈哈村的跳棋比赛 题解:其实我们要理解题意就好了,画画图看看这个题意.x<y,那么就交换:x>y,那么x=x%y. 如果我们经过很多次,或者y<=0了,那么就会无限循环 ...
- 喵哈哈村的魔法考试 Round #18 (Div.2) 题解
喵哈哈村的古怪石碑(一) 题解:暴力check一下是等比数列还是等差数列,然后输出答案即可.注意如果数据范围是1e9的话,就要快速幂了. 代码: #include <cstdio> #in ...
- 喵哈哈村的魔法考试 Round #13 (Div.2) 题解
喵哈哈村的木星传说(一) 旋转90°,找找规律就知道(x,y)->(n-1-y,x) 然后输出就好了. #include<bits/stdc++.h> using namespace ...
随机推荐
- 如何查看centos系统cpu/内存使用情况
1.查看硬盘 [mushme@investide ~]$ df -ah 文件系统 容量 已用 可用 已用% 挂载点 /dev/cciss/c0d0p1 123G ...
- 【Android开源库】美团等APP城市选择
CityPicker 现在使用比较多的类似美团等APP的城市选择界面. 2步即可实现,就是这么简单粗暴! Gif image APK 下载demo.apk体验. Install Gradle: com ...
- Vue项目启动后首页URL带的#该怎么去掉?
修改router的mode为history就可以 const router = new VueRouter({mode: 'history', routes: [...]}) 实际修改后需要注意修改a ...
- ipython+notebook使用教程(转载)
ipython是python交互环境的增强版 IPython notebook目前已经成为用Python做教学.计算.科研的一个重要工具.IPython Notebook使用浏览器作为界面,向后台的I ...
- Elasticsearch创建索引和映射结构详解
前言 这篇文章详细介绍了如何创建索引和某个类型的映射. 下文中[address]指代elasticsearch服务器访问地址(http://localhost:9200). 1 创建索引 ...
- NBUT1457
不知道哪里的oj..做了交不上去.. 也是莫队的模板题 #include<iostream> #include<cstring> #include<cstdio> ...
- 在IDEA中实战Git
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程git仓库上获取项目源码 场景三:小 ...
- 实现数据导出为.csv表格
数据导出实现步骤: 1.查找出要导出的数据,整理为二维数组. 2.定义导出表格的字段 3.将整理的二维数组按导出表格定义的字段重新整理. 4.将整理的二维数组写入服务器中已有的一个.csv文件. 5. ...
- Spring启动研究2.AbstractApplicationContext.obtainFreshBeanFactory()研究
据说这个方法里面调用了loadBeanDefinitions,据说很重要,并且跟我感兴趣的标签解析有关,所以仔细看看 obtainFreshBeanFactory()这个方法在AbstractAppl ...
- PostgreSQL的SQL语句中的双引号引发的问题
最近开发一个WEB的ETL工具需要用到不同的数据源.第一次用POSTGRESQL发现一个双引号引发的问题: 标准的SQL是不区分大小写的.但是PostgreSQL对于数据库中对象的名字允许使用支持大小 ...