外面吵得风生水起,我校平静地在打比赛,丝毫不知道这次比赛的题目就是把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. 弱势图解AC自动机

    本篇文章主要详细介绍$AC$自动机的$fail$指针: 如果有什么不完善的地方,请联系我$qwq$ 前置知识: 1.建议学一下$kmp$算法 2.$Trie$ 导入: AC自动机是用来解决多模板匹配问 ...

  2. 小米 oj 马走日 (bfs 或 双向bfs)

     马走日 序号:#56难度:困难时间限制:1500ms内存限制:10M 描述 在中国象棋中,马只能走日字型.现在给出一个由 N*M 个格子组成的中国象棋棋盘( 有(N+1)*(M+1)个交叉点可以落子 ...

  3. hdu 4810 Wall Painting (组合数+分类数位统计)

    Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  4. (转载)IOCP 浅析

    转自:http://www.ibm.com/developerworks/cn/java/j-lo-iocp/#author   郭 仁祥, 软件工程师, IBM 简介: 传统的 Server/Cli ...

  5. (转载)完成端口(CompletionPort)详解 - 手把手教你玩转网络编程系列之三

    转自:http://blog.csdn.net/piggyxp/article/details/6922277 前 言 本系列里完成端口的代码在两年前就已经写好了,但是由于许久没有写东西了,不知该如何 ...

  6. Going Deeper with Convolutions阅读摘要

      论文链接:Going deeper with convolutions 代码下载: Abstract We propose a deep convolutional neural network ...

  7. 【Makefile】Makefile中的常用函数简介

    1. subst函数 格式:$(subst <from>, <to>, <text>)功能:把字串<text>中的<from>字符串替换成& ...

  8. Python - 排序( 插入, 冒泡, 快速, 二分 )

    插入排序 算法分析 两次循环, 大循环对队列中的每一个元素拿出来作为小循环的裁定对象 小循环对堆当前循环对象在有序队列中寻找插入的位置 性能参数 空间复杂度 O(1) 时间复杂度 O(n^2) 详细代 ...

  9. 计算机组成原理 — FPGA 现场可编程门阵列

    目录 文章目录 目录 FPGA FPGA 的应用场景 FPGA 的技术难点 FPGA 的工作原理 FPGA 的体系结构 FPGA 的开发 FPGA 的使用 FPGA 的优缺点 参考文档 FPGA FP ...

  10. requestLibrary API

    requestLibrary API Keyword Arguments Documentation Create Ntlm Session alias, url, auth, headers={}, ...