本来今天晚上拿13年NOIP的题目来做一下,测测能够得多少分,结果一晚上把Day1写完竟然AK了,吼吼吼

  D1T1,题目:http://codevs.cn/problem/3285/

  很水的一道快速幂啊,题目竟然还刚好有0号节点来降低难度,记住对于转圈之后的位置要往取模方面想

  ans=(x+m*10k)%n,原本是x号位置,每次往前走m个位置,共走了10k,最后再对于圈的大小取模即为最终位置

  模意义下可变形,ans=x+m*10k%n=x+m*(10k%n)%n

  其中10k%n不就是个快速幂取模吗?直接上模板:http://www.cnblogs.com/hadilo/p/5719139.html

  简单AC

 // Copyright(c) Hadilo.All Rights Reserved.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#define fre(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
typedef long long LL;
typedef double db;
const long double CPS=CLOCKS_PER_SEC,TL=0.998;
const int oo=;
inline int read()
{
int re=;
bool fu=;
char ch=getchar();
while ((ch>''||ch<'')&&ch!='-') ch=getchar();
if (ch=='-')
{
fu=;
ch=getchar();
}
while (ch>=''&&ch<='')
{
re=re*+ch-'';
ch=getchar();
}
return fu?-re:re;
}
int n;
inline int mi(LL a,int b)
{
LL k=;
a%=n;
while (b)
{
if (b&) k=k*a%n;
b>>=;
a=a*a%n;
}
return (int)k;
}
int main()
{
fre("circle");
n=read();
cout<<(read()*mi(,read())+read())%n<<endl;
return ;
}

  D1T2,题目:http://codevs.cn/problem/3286/

  其实看完题目我是先写的T3再写的T2,因为感觉这个不是太好证明

  可伪证一下,把两个数组排序后对应位置即为最终答案,因为找不出反例而且感觉很正确

  则对于两个数组a、b分别离散化一下,再记一个数组c[i]为b[i]离散化的值在a[i]中的位置

  最后对 c 数组求逆序对即可,归并排序或树状数组都可以,我写的是归并排序

 // Copyright(c) Hadilo.All Rights Reserved.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#define fre(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
typedef long long LL;
typedef double db;
const long double CPS=CLOCKS_PER_SEC,TL=0.998;
const int oo=,N=,mo=;
inline int read()
{
int re=;
bool fu=;
char ch=getchar();
while ((ch>''||ch<'')&&ch!='-') ch=getchar();
if (ch=='-')
{
fu=;
ch=getchar();
}
while (ch>=''&&ch<='')
{
re=re*+ch-'';
ch=getchar();
}
return fu?-re:re;
}
struct gap
{
int x,num;
};
gap a[N];
int b[N],c[N],p[N],ans;
inline void gb(int l,int r)
{
if (l==r) return;
int mid=(l+r)>>,i,j,top=;
gb(l,mid);
gb(mid+,r);
for (i=l,j=mid+;i<=mid&&j<=r;)
{
if (c[i]<=c[j]) b[++top]=c[i++];
else
{
b[++top]=c[j++];
if ((ans+=mid-i+)>mo) ans-=mo;
}
}
while (i<=mid) b[++top]=c[i++];
while (j<=r) b[++top]=c[j++];
for (;top;top--,r--) c[r]=b[top];
}
inline bool cmp(gap x,gap y)
{
return x.x<y.x;
}
int main()
{
fre("math");
int i,n=read();
for (i=;i<=n;i++) a[i]=(struct gap){read(),i};
sort(a+,a+i,cmp);
for (i=;i<=n;i++)
{
b[a[i].num]=i;
p[i]=a[i].num;
a[i]=(struct gap){read(),i};
}
sort(a+,a+i,cmp);
for (i=;i<=n;i++) c[a[i].num]=p[i];
gb(,n);
printf("%d\n",ans);
return ;
}

  D1T3,题目:http://codevs.cn/problem/3287/

  题目要求路径上的所有边权的最小值最大

  对于两点之间的路径,不就是走最大的那几个边可以保证答案最大

  而在一棵树中是能保证图刚好连通的,做一颗最大生成树

  然后对于每组询问直接倍增求LCA即可,记得统计路径上的边权最小值

 // Copyright(c) Hadilo.All Rights Reserved.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#define fre(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
typedef long long LL;
typedef double db;
const long double CPS=CLOCKS_PER_SEC,TL=0.998;
const int oo=,N=,M=,L=,N2=;
inline int read()
{
int re=;
bool fu=;
char ch=getchar();
while ((ch>''||ch<'')&&ch!='-') ch=getchar();
if (ch=='-')
{
fu=;
ch=getchar();
}
while (ch>=''&&ch<='')
{
re=re*+ch-'';
ch=getchar();
}
return fu?-re:re;
}
struct gap
{
int u,v,w;
};
gap e[M];
int first[N],f[N][L],g[N][L],next[N2],v[N2],w[N2],d[N],fa[N],t;
inline int log2(int x)
{
int k=-;
while (x)
{
k++;
x>>=;
}
return k;
}
inline int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void dfs(int x,int last)
{
if (last) fa[x]=find(last);
t=max(t,d[x]=d[last]+);
f[x][]=last;
for (int i=first[x];i;i=next[i])
if (v[i]!=last)
{
g[v[i]][]=w[i];
dfs(v[i],x);
}
}
inline bool cmp(gap x,gap y)
{
return x.w>y.w;
}
int main()
{
fre("truck");
int n=read(),m=read(),i,j,x,y,top=,ans;
for (i=;i<=m;i++) e[i]=(struct gap){read(),read(),read()};
sort(e+,e++m,cmp);
for (i=;i<=n;i++) fa[i]=i;
for (i=;i<=m;i++)
{
x=find(e[i].u);
y=find(e[i].v);
if (x!=y)
{
fa[x]=y;
top++;
next[top]=first[v[top+n]=e[i].u];
first[e[i].u]=top;
next[top+n]=first[v[top]=e[i].v];
first[e[i].v]=top+n;
w[top]=w[top+n]=e[i].w;
}
}
for (i=;i<=n;i++) fa[i]=i;
for (i=;i<=n;i++) if (fa[i]==i) dfs(i,);
t=log2(t);
for (i=;i<=t;i++)
for (j=;j<=n;j++)
{
f[j][i]=f[f[j][i-]][i-];
g[j][i]=min(g[j][i-],g[f[j][i-]][i-]);
}
m=read();
while (m--)
{
x=read();
y=read();
if (find(x)==find(y))
{
ans=oo;
if (d[x]<d[y]) swap(x,y);
for (i=log2(d[x]-d[y]);i>=;i--)
if (f[x][i]&&d[f[x][i]]>=d[y])
{
ans=min(ans,g[x][i]);
x=f[x][i];
}
if (x==y)
{
printf("%d\n",ans);
continue;
}
for (i=log2(d[x]);i>=;i--)
if (f[x][i]&&f[x][i]!=f[y][i])
{
ans=min(ans,min(g[x][i],g[y][i]));
x=f[x][i];
y=f[y][i];
}
printf("%d\n",min(ans,min(g[x][],g[y][])));
}
else printf("-1\n");
}
return ;
}

版权所有,转载请联系作者,违者必究

联系方式:http://www.cnblogs.com/hadilo/p/5932395.html

NOIP2013Day1解题报告的更多相关文章

  1. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  2. 二模13day1解题报告

    二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...

  3. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

  4. 习题:codevs 2822 爱在心中 解题报告

    这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...

  5. 习题:codevs 1035 火车停留解题报告

    本蒟蒻又来写解题报告了.这次的题目是codevs 1035 火车停留. 题目大意就是给m个火车的到达时间.停留时间和车载货物的价值,车站有n个车道,而火车停留一次车站就会从车载货物价值中获得1%的利润 ...

  6. 习题: codevs 2492 上帝造题的七分钟2 解题报告

    这道题是受到大犇MagHSK的启发我才得以想出来的,蒟蒻觉得自己的代码跟MagHSK大犇的代码完全比不上,所以这里蒟蒻就套用了MagHSK大犇的代码(大家可以关注下我的博客,友情链接就是大犇MagHS ...

  7. 习题:codevs 1519 过路费 解题报告

    今天拿了这道题目练练手,感觉自己代码能力又增强了不少: 我的思路跟别人可能不一样. 首先我们很容易就能看出,我们需要的边就是最小生成树算法kruskal算法求出来的边,其余的边都可以删掉,于是就有了这 ...

  8. NOIP2016提高组解题报告

    NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合

  9. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

随机推荐

  1. c# win form 显示支付宝二维码图片

    System.Net.WebClient web = new System.Net.WebClient(); byte[] buffer = web.DownloadData(网络图片的地址); we ...

  2. 剑指offer系列44---只出现一次 的数字

    [题目]一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. * [思路]异或性质:数异或自己即为0: * 一个数组中,从头到尾异或的结果为不重复数字异或结果. ...

  3. json换行符的处理

    JS端的: var s = JSON.stringify(str); var ss = s.replace(/\\n/g, "\\n") .replace(/\\'/g, &quo ...

  4. html body标签的几个属性 禁用鼠标右键,禁用鼠标选中文字等

    <body oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onsel ...

  5. Python输入和输出

    在很多时候,你会想要让你的程序与用户(可能是你自己)交互.你会从用户那里得到输入,然后打印一些结果.我们可以分别使用raw_input和print语句来完成这些功能.对于输出,你也可以使用多种多样的s ...

  6. iphone Dev 开发实例9:Create Grid Layout Using UICollectionView in iOS 6

    In this tutorial, we will build a simple app to display a collection of recipe photos in grid layout ...

  7. PLSQL_Oracle PLSQL处理日期方式大全(概念)

    TO_DATE格式  Day:  dd number 12  dy abbreviated fri  day spelled out friday  ddspth spelled out, ordin ...

  8. NeHe OpenGL教程 第九课:移动图像

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  9. [复变函数]第05堂课 1.4 复球面与 $\infty$; 作业讲解; 2 解析函数 2.1 解析函数的概念与 Cauchy-Riemann 方程

    1. 复球面 大漠孤烟直, 长河落日圆. $$\bex \bbC\cong \bbS^2\bs \sed{N},\quad \bbC_\infty=\bbC\cup \sed{\infty}\mbox ...

  10. SteamVR Unity工具包(VRTK)之控制器交互

    可交互对象(VRTK_InteractableObject) 可交互对象脚本被添加到需要用(如控制器)来交互的任何游戏对象上.   可用脚本参数如下   Touch Interactions 触摸交互 ...