外面吵得风生水起,我校平静地在打比赛,丝毫不知道这次比赛的题目就是把2018银川邀请赛的题照搬过来了QAQ,主办方真牛逼。。

A Maximum(思维)

题意:维护一个栈,支持入栈和出栈操作,并计算每次操作后的栈中最大值,得到最终结果。

思路:

  这题真的是,我和hxc轮流做这道题,被坑惨了,一直以为使用数据结构来做,没想到点上去。思维题,每次保证栈顶为栈中最大元素。如果当前入栈的元素为x,当前栈顶元素为y,如果x>=y,这个没问题,直接入栈就行了; 如果x<y,我们相当于直接用y替换x,再入栈即可。

  吸取教训,这种过的人很多的,不要想复杂,怎么简单怎么来。

AC代码:

#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
using namespace std; const int maxn=5e6+;
typedef unsigned int UI;
int T,cas,top;
UI stk[maxn];
long long ans; int n,p,q,m;
unsigned int SA,SB,SC;
unsigned int rng61(){
SA^=SA<<;
SA^=SA>>;
SA^=SA<<;
unsigned int t=SA; SA=SB;
SB=SC;
SC^=t^SA;
return SC;
} void gen(){
scanf("%d%d%d%d%u%u%u",&n,&p,&q,&m,&SA,&SB,&SC);
for(int i=;i<=n;++i){
if(rng61()%(p+q)<p){
stk[++top]=rng61()%m+;
stk[top]=max(stk[top-],stk[top]);
}
else
if(top>) --top;
ans^=1LL*i*stk[top];
}
} int main(){
scanf("%d",&T);
while(T--){
ans=;
top=;
gen();
printf("Case #%d: %lld\n",++cas,ans);
}
return ;
}

B. Rolling The Polygon

hxc写得。

AC代码:

#pragma GCC optimize(2)
#include <cstdio>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <cassert>
#define ll long long
#define R register int
#define I inline void
#define lc c[x][0]
#define rc c[x][1] using namespace std;
const int INF = 0x3f3f3f3f; const int maxn = ;
struct node
{
double x,y;
}pp[maxn],qq; double rad(node a,node b,node c)
{
return acos(((a.x - b.x) * (c.x - b.x) + (a.y - b.y) * (c.y - b.y)) / sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) / sqrt((c.x - b.x) * (c.x - b.x) + (c.y - b.y) * (c.y - b.y)));
} int t,n;
int main()
{
scanf("%d",&t);
int o = t;
while(t--)
{
double ans = ;
scanf("%d",&n);
for(int i = ; i <= n; i++)
scanf("%lf%lf",&pp[i].x,&pp[i].y);
scanf("%lf%lf",&qq.x,&qq.y); for(int i = ; i <= n; i++)
{
//printf("%qwe%lf\n",rad(pp[(i - 2 + n * 2) % n + 1],pp[i],pp[i % n + 1]));
double temp = sqrt((qq.x - pp[i].x) * (qq.x - pp[i].x) + (qq.y - pp[i].y) * (qq.y - pp[i].y));
ans += temp * (M_PI - rad(pp[(i - + n * ) % n + ],pp[i],pp[i % n + ]));
}
printf("Case #%d: %.3lf\n",o - t,ans);
}
}

C. Ceasar Cipher (水题,模拟就行了)

AC代码:

#include<cstdio>
#include<algorithm>
using namespace std; int T,n,m,cas,num;
char s1[],s2[],s3[]; int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
scanf("%s%s%s",s1,s2,s3);
num=(s1[]-s2[]+)%;
printf("Case #%d: ",++cas);
for(int i=;i<m;++i)
printf("%c",(s3[i]-'A'+num)%+'A');
printf("\n");
}
return ;
}

D. Moving On (概率)

题意:

  第一问:n个人对应n个座位,按1~n的顺序选择,1号任意选,i号选i(如果i未选)或任意选(如果i已选),i>=2,求最后一个选的人选对的概率。

  第二问:m个人对应m个座位,按任意次序选择(m!种排列),1号任意选,i号选i(如果i未选)或任意选(如果i已选),i>=2,求最后一个选的人选对的概率。

思路:

  第一问dfs打表发现概率为0.5,第二种情况对于m!种排列:

    如果1在最后选,那么一定能选对,概率为1,有(m-1)!种。

    如果1不在最后,1前面的一定能选对,从1开始往后的就变成第1问,概率为0.5,有m!-(m-1)!种。

  故第二种概率为(m-1)!/m!*1+(m!-(m-1)!)/m!*0.5=(m+1)/(2*m)。

刚开始算错了,卡了两小时QAQ。。

AC代码:

#include<cstdio>
#include<algorithm>
using namespace std; int T,n,m,cas; int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
printf("Case #%d: ",++cas);
if(n==) printf("1.000000 ");
else printf("0.500000 ");
printf("%.6f\n",1.0*(m+)/(2.0*m));
}
return ;
}

F. Moving On(floyd变形)

题意:给定一个图,每个点有个权值r[i],多次询问,每次询问u到v的最短路,且该最短路不经过权值大于w的点。

思路:按权值进行排序,然后floyd,dp[k][i][j]表示经过排序后的前k个点i到j的最短路。询问的时候二分查找即可。但是这题似乎卡常,我定义数组dp[i][j][k]会T,而dp[k][i][j]就A了。绝望-_-。。

AC代码:

#include<cstdio>
#include<algorithm>
using namespace std; const int maxn=;
const int inf=0x3f3f3f3f;
int T,cas,n,m;
int u,v,w,dp[maxn][maxn][maxn]; struct node{
int val,id;
}a[maxn]; bool operator < (const node& x,const node& y){
return x.val<y.val;
} int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i){
scanf("%d",&a[i].val);
a[i].id=i;
}
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
scanf("%d",&dp[][i][j]);
sort(a+,a+n+);
for(int k=;k<=n;++k)
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
dp[k][i][j]=min(dp[k-][i][j],dp[k-][i][a[k].id]+dp[k-][a[k].id][j]);
printf("Case #%d:\n",++cas);
while(m--){
scanf("%d%d%d",&u,&v,&w);
int l=,r=n,mid;
while(l<=r){
mid=(l+r)>>;
if(a[mid].val<=w) l=mid+;
else r=mid-;
}
printf("%d\n",dp[r][u][v]);
}
}
return ;
}

2019icpc银川网络赛的更多相关文章

  1. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  2. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  3. 2019icpc南京网络赛_F_Greedy Sequence

    题意 题意不明,队友告诉我对于每个\(i\),所在下标\(p[i]\),在\([p[i]-k,p[i]+k]\)中找到小于\(i\)的最大数\(x\),然后\(ans[i]=ans[x]+1\)即可. ...

  4. 2019icpc南昌网络赛_I_Yukino With Subinterval

    题意 给定一个序列,两种操作,单点修改,询问区间\([l,r]\)值域在\([x,y]\)范围内的连续段个数. 分析 原数组为\(a\),构造一个新的数组\(b\),\(b[i]=(a[i]==a[i ...

  5. 2019icpc徐州网络赛_I_query

    题意 给定一个序列,多次询问区间\([l,r]\)中满足\(min(a[i],a[j])==gcd(a[i],a[j])\)的数对\((i,j)\)数. 分析 其实就是求区间有倍数关系的数对数. 由于 ...

  6. 2019ICPC 上海网络赛 G题 Substring(哈希)

    题意: 给了一个母串S, 每次循环给了一个模板串,问模板串在母 串中“匹配”了多少次?“匹配”的意思就是首字母和尾字母一样, 中间字母顺序可以换. 题解: 字符串hash.我们将询问字符串的首尾特殊h ...

  7. 2019ICPC徐州网络赛 A.Who is better?——斐波那契博弈&&扩展中国剩余定理

    题意 有一堆石子,两个顶尖聪明的人玩游戏,先取者可以取走任意多个,但不能全取完,以后每人取的石子数不能超过上个人的两倍.石子的个数是通过模方程组给出的. 题目链接 分析 斐波那契博弈有结论:当且仅当石 ...

  8. 2019ICPC南京网络赛B super_log——扩展欧拉定理

    题目 设函数 $$log_a*(x) = \begin{cases}-1, & \text{ if } x < 1 \\ 1+log_a*(log_ax) & \text{ if ...

  9. 2019ICPC南昌网络赛总结

    打的很崩的一场比赛.上来签到题我就wa了一发,感觉在梦游.然后我开了H题,队友开B题,f(n)=3f(n-1)+2f(n)傻子都知道矩阵快速幂,但是1e7的强制在线必须把logn优化,然后试图打表寻找 ...

随机推荐

  1. centos 升级内核方法

    方法1:rpm安装方式 rpm安装包可以通过这个网站下载: 这个是CentOS6 x64 : http://elrepo.org/linux/kernel/el6/x86_64/RPMS/ 这个是Ce ...

  2. frontEnd(前端基础)

    第一章:前端概述 第二章:前端三剑客 第三章:第一个页面 第四章:html常用标签 第五章:标签分类 第六章:css三种引入方式 第七章:样式与长度颜色 第八章:常用样式 第九章:CSS选择器 第十章 ...

  3. luogu 1220 关路灯 区间dp

    Code: #include <bits/stdc++.h> #define ll long long #define N 1003 #define setIO(s) freopen(s& ...

  4. [Cogs] 最大数maxnumber

    http://cogs.pro:8080/cogs/problem/problem.php?pid=1844 Luogu 的数据真zhizhang Cogs AC #include <iostr ...

  5. 【CUDA 基础】6.0 流和并发

    title: [CUDA 基础]6.0 流和并发 categories: - CUDA - Freshman tags: - 流 - 事件 - 网格级并行 - 同步机制 - NVVP toc: tru ...

  6. Manacher 算法学习小记

    概要 一个字符串有多少个回文的字串?最多有 \(O(n^2)\) 级别个.但 Manacher 算法却可以用 \(O(n)\) 的时间复杂度解决这个问题.同时 Manacher 算法实现非常简单. 一 ...

  7. OpenGL 开发环境配置:Visual Studio 2017 + GLFW + GLEW

    Step1:Visual Studio 2017 Why 开发环境,后面编译GLFW 和 GLEW也要用 How 这里使用的是Visual Studio 2017的 Community 版本,直接官网 ...

  8. 前端工程师需要掌握的 Babel 知识

    在前端圈子里,对于 Babel,大家肯定都比较熟悉了.如果哪天少了它,对于前端工程师来说肯定是个噩梦.Babel 的工作原理是怎样的可能了解的人就不太多了.本文将主要介绍 Babel 的工作原理以及怎 ...

  9. IDEA checkout Git 分支 弹出 Git Checkout Problem

    1. 本地分支切换的时候(例如A切到B),会弹出来Restore workspace on branch switching 对话框,如果选择是的话,在切换分支的时候,你在当前分支(A)所做的一些还未 ...

  10. HearthBuddy遇奥秘解决方法

    https://tieba.baidu.com/g/5808796816 链接: https://pan.baidu.com/s/1NPQTOfxbN_4alP7J-XWuVw 密码: xfj1