当前位置: 首页 > 编程日记 > 正文

Codeforces Round #370 (Div. 2)

A - Memory and Crow

这题我没看题意,看了样例猜了一下就AC了,题目好像还挺复杂的。

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{int n;cin>>n;for(int i=1;i<=n;i++) scanf("%d",&a[i]);for(int i=1;i<n;i++) printf("%d ",a[i]+a[i+1]);printf("%d\n",a[n]);return 0;
}
View Code

 B - Memory and Trident

题目大意:一个人可以往上下左右走,给你一串操作,问你最少改变几个能回到原地。

思路:将上下分成一堆,左右分成一堆,改变的时候优先同一堆里面的互换。这样能

保证次数最少。代码写的有点搓。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char s[N];
int vis[4];
int main()
{scanf("%s",s);int len=strlen(s);if(len%2){puts("-1");return 0;}for(int i=0;i<len;i++){if(s[i]=='U') vis[0]++;else if(s[i]=='D') vis[1]++;else if(s[i]=='L') vis[2]++;else vis[3]++;}if((vis[0]+vis[1])%2==0){int a=(vis[0]+vis[1])/2-min(vis[0],vis[1]);int b=(vis[2]+vis[3])/2-min(vis[2],vis[3]);cout<<a+b<<endl;}else{int a=(vis[0]+vis[1]-1)/2-min(vis[0],vis[1]);//cout<<a<<endl;int b=(vis[2]+vis[3]-1)/2-min(vis[2],vis[3]);cout<<a+b+1<<endl;}return 0;
}
View Code

C - Memory and De-Evolution

题目大意:给你两个边长分别为x和y的等边三角形,问你最少通过多少次改变可以把x变成y(x>y)

每次改变可以改变一条边,且改变后三边依旧能构成三角形。

思路:想了一会就想出来了,反过来模拟,从y模拟到x,每次y都取出最小的边把它变成能变成

的最大值,等到最小的边都大于x了就结束。

#include<bits/stdc++.h>
using namespace std;
int x,y;
int a[3];
int main()
{cin>>x>>y;a[0]=a[1]=a[2]=y;int i=0;int ans=0;for(;;i++){ans++;a[i%3]=a[(i+1)%3]+a[(i+2)%3]-1;//printf("%d %d %d\n",a[0],a[1],a[2]);if(min(a[(i+1)%3],a[(i+2)%3])>=x) break;}cout<<ans<<endl;return 0;
}
View Code

D - Memory and Scores

题目大意:两个人有初试分数a和b,有 t  轮游戏,每轮游戏每人随机得到[-k,k]中的一个数加

到自己的分数中,问你k轮以后,有多少个结果是 第一个人得分数大于第二个人的。结果对1e9+7取模。

思路:用dp[i][j] 表示进行到 i 轮,分数为得到的分数为j 的方案数。

状态转移方程,dp[i][j]=dp[i-1] [j-k]+dp[i-1][j-k+1]+...+dp[i-1][j+k]。

直接这样写可能会超时,我们考虑用前缀和优化,即每一轮更新

的时候保存当前轮dp的前缀和,用于更新下一轮。最后就是计算

方案总数的问题了。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2*1e5+1;
ll dp[101][N],a[N],b[N];
ll x,y,k,t;
const ll mod=1e9+7;
int main()
{cin>>x>>y>>k>>t;ll up=k*t*2;dp[0][k*t]=1;for(ll i=0;i<=up;i++){if(i==0) a[i]=dp[0][i];else a[i]=a[i-1]+dp[0][i];}ll *p=a,*q=b,*g;for(ll i=1;i<=t;i++){for(ll j=0;j<=up;j++){ll l=j-k,r=j+k;l=max((ll)0,l);r=min(up,r);ll t=dp[i][j];if(l==0) dp[i][j]=(dp[i][j]+p[r])%mod;else dp[i][j]=(dp[i][j]+p[r]-p[l-1]+mod)%mod;if(j==0) q[j]=dp[i][j]%mod;else q[j]=(dp[i][j]+q[j-1])%mod;}g=q;q=p;p=g;}ll ans=0;ll dis=y-x+1;for(ll i=0;i<=up;i++){ll now=i-dis;if(now>up) now=up;if(now>=0) ans=(ans+((dp[t][i])*p[now])%mod)%mod;}cout<<ans%mod<<endl;return 0;
}
View Code

E - Memory and Casinos

题目大意:有n个赌场,每个赌场你赢的概率为p,如果赢了你往右边的赌场走,输了往左边的赌场走,

给你一个范围 l 到 r 问你从 l 开始,最后在 r 赢且不在 l 输的概率是多少,写的时候真的不知道怎么写。。

还是太菜了。

思路:我们可以用线段树进行区间合并,我们记L( l , r )为从 l 开始最后在r赢不在且在 l 永远不输的概率,

R( l , r )为从 r 开始,最后在 r 赢,且永远不在 l 输的概率。我们对线段树的每个节点保存当前区间的这

两个值,每个节点保存该区间的 L 和 R 值。那么两个区间该如何合并呢?

我们可以先考虑只有两个点的情况 a 点和 b 点,求从 a 开始,最终在 b 点赢,且在 a 点永远不输的概率,

且 在 a 点赢的概率为p1,b 点为 p2,那么我们可以知道我们要求的概率就是一下式子的和

p1*p2         a(win)   b(win)

p1 * ( ( 1 - p2 ) * p1 ) * p2        a(win) b(lose) a(win) b(win)

p1 * ( ( 1 - p2 ) * p1)^2 * p2     a(w) ( b(l)  a(w)  b(l)  a(w) ) b(w)

.............

p1 * ( ( 1 - p2 ) * p1)^n * p2

求和就是等比数列求和。

那么对于两个区间也是同理,对于两个区间a,b,他们的L,R分别为  L1 , L2 , R1  R2,合并之后的 L 为 L3  R 为 R3

那么 L3 为以下式子的和

L1 * L2

L1 * ( ( 1 - L2 ) * R1 ) * L2

L1 * ( ( 1 - L2 ) * R1 )^2  * L2

............

L1 * ( ( 1 - L2 ) * R1 ) ^n * L2

R3 为以下式子的和

R2

( 1 - R2 ) * R1 * L2

( 1 - R2 ) * R1 *( ( 1 - L2 ) * R1 ) * L2

( 1 - R2 ) * R1 *( ( 1 - L2 ) * R1 )^2 * L2

.............

( 1 - R2 ) * R1 *( ( 1 - L2 ) * R1 )^n * L2

这样就能完成线段树的区间合并了。

#include<bits/stdc++.h>
#define pdd pair<double,double>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
const int N=1e5+5;
pdd st[N<<2];
int n,q;
pdd Merge(pdd x,pdd y)
{pdd ans;ans.fi=(x.fi*y.fi)/(1.0-x.se*(1.0-y.fi));ans.se=y.se+((1.0-y.se)*x.se*y.fi)/(1.0-(1.0-y.fi)*x.se);return ans;
}
void build(int l,int r,int rt)
{if(l==r){double a,b;scanf("%lf%lf",&a,&b);st[rt].fi=a/b; st[rt].se=a/b;return;}int m=(l+r)>>1;build(lson);build(rson);st[rt]=Merge(st[ls],st[rs]);
}
void updata(int l,int r,int rt,int x,double a,double b)
{if(l==r && r==x){st[rt].fi=a/b;st[rt].se=a/b;return;}int m=(l+r)>>1;if(x<=m) updata(lson,x,a,b);else updata(rson,x,a,b);st[rt]=Merge(st[ls],st[rs]);
}
pdd query(int L,int R,int l,int r,int rt)
{if(l>=L && r<=R) return st[rt];int m=(l+r)>>1;if(R<=m) return query(L,R,lson);else if(L>m) return query(L,R,rson);else return Merge(query(L,R,lson),query(L,R,rson));
}
int main()
{cin>>n>>q;build(1,n,1);while(q--){int op;scanf("%d",&op);if(op==1){int  x;double a,b;scanf("%d%lf%lf",&x,&a,&b);updata(1,n,1,x,a,b);}else{int l,r;scanf("%d%d",&l,&r);pdd ans=query(l,r,1,n,1);printf("%.12f\n",ans.fi);}}return 0;
}
View Code

转载于:https://www.cnblogs.com/CJLHY/p/7240669.html

相关文章:

pat1004. Counting Leaves (30)

1004. Counting Leaves (30) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Each input file contains…

css 引用字体

最近遇到个问题&#xff0c;页面使用的字体要用PingFangSC字体&#xff0c;引入方法如下&#xff1a; 简单介绍下PingFangSC字体&#xff1a; &#xff08;1&#xff09;苹方-简 常规体 font-family: PingFangSC-Regular, sans-serif; &#xff08;2&#xff09;苹方…

系统技术方案 系统构架_构架系统时应注意的事项

系统技术方案 系统构架by Ayelet Sachto通过Ayelet Sachto 架构系统时要记住的6件事 (6 Things to keep in mind when architecting a system) Architecture may sound like a “scary ” or overwhelming subject, but actually, applying logic and approaching the problem…

[LeetCode] Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num 38, the process is like: 3 8 11, 1 1 2. Since 2 has only one digit, return it. 分析一&#xff1a;最简单的循环方法 class Solutio…

vue 点击事件执行多次

把 click 改成 click.once 就可以了 示例代码 click.once"down" 这样有一个弊端&#xff0c;就是事件只执行一次就不再执行了&#xff0c; 另一种方式&#xff0c;做一个定时器 //默认设置dddown为 true if(that.dddown){that.dddown falsesetTimeout(function(…

如何以及为什么使用Android Visibility Listeners

The Android UI is built up from Views, and in a regular application, there are usually several of them. To find out which View the user is currently looking at, you need to install Visibility Listeners.Android UI是从Views构建的&#xff0c;在常规应用程序中&…

在vue中使用Element-UI

Element-UI是一套基于Vue2.0的UI组件库&#xff0c;http://element.eleme.io/#/zh-CN/component/carousel 首先npm install element-ui --save 然后在main.js中引入&#xff1a; import Vue from vue import ElementUI from element-ui import element-ui/lib/theme-default/in…

Flex布局教程(来源:阮一峰)

网页布局&#xff08;layout&#xff09;是 CSS 的一个重点应用。Flex 布局将成为未来布局的首选方案。本文介绍它的语法&#xff0c;下一篇文章给出常见布局的 Flex 写法。网友 JailBreak 为本文的所有示例制作了 Demo&#xff0c;也可以参考。 以下内容主要参考了下面两篇文…

ibatis的there is no statement named xxx in this SqlMap

报错情况如下&#xff1a;com.ibatis.sqlmap.client.SqlMapException: There is no statement named Control.insert-control in this SqlMap. at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)at com.ibatis.sq…

javascript案例_如何在JavaScript中使用增强现实-一个案例研究

javascript案例by Apurav Chauhan通过Apurav Chauhan 如何在JavaScript中使用增强现实-一个案例研究 (How to use Augmented Reality with JavaScript — a case study) In this experiment, I talk about how Augmented Reality with JS can be used to make learning more f…

久未更 ~ 一之 —— 关于ToolBar

很久没更博客了&#xff0c;索性开一个久未更 系列 > > > > > 久未更 系列一&#xff1a;关于ToolBar的使用(后续补充) 1 //让 ToolBar 单独使用深色主题 使得 toolbar 中元素 变为淡色 2 android:theme"style/ThemeOverlay.AppCompat.Dark.ActionBar"…

SQLServer怎样把本地数据导入到远程服务器上(转载)

平常用到mssql时间比较少&#xff0c;总是过一段时间就忘记应该怎么操作了。当要做mssq把本地数据导入到远程服务器的时候&#xff0c;就去网上搜索很久都没有图解的&#xff0c;所以今天自己收集一下免得下次又到处去找。希望对自己&#xff0c;同时对其它需要的人都有一定的帮…

input 默认样式的修改

/* 修改input选中的默认边框样式 */ outline: none; /* 修改input的选中时的光标颜色 */ caret-color:red; /* 修改input的选中时的默认边框 */ border: none; /* 修改input的提示文字的默认样式 */ input::-webkit-input-placeholder{color:#d0d0d0;}

巨石加密_点餐:如何吃一个可怕的巨石

巨石加密by Alan Ridlehoover通过艾伦里德尔霍弗 点餐&#xff1a;如何吃一个可怕的巨石 (Ordering Take Out: How to Eat a Scary Monolith) Martin Fowler said:马丁福勒(Martin Fowler) 说 &#xff1a; Almost all the successful microservice stories have started wit…

Halcon学习之六:获取Image图像中Region区域的特征参数

area_center_gray ( Regions, Image : : : Area, Row, Column ) 计算Image图像中Region区域的面积Area和重心&#xff08;Row&#xff0c;Column&#xff09;。 cooc_feature_image ( Regions, Image : : LdGray, Direction : Energy,Correlation, Homogeneity, Contrast ) …

dos下命令行执行程序时候注意程序所使用文件的路径问题

dos下命令行执行程序时候&#xff0c;最好是用cd命令先切换到程序所在目录下&#xff0c;这样就不会出现文件找不到的问题&#xff0c;如果由于特殊原因&#xff0c;不使用cd命令&#xff0c;而只使用路径命令时候程序中访问的资源也只能是改成绝对路径了&#xff0c;这样对有源…

Vant 使用之Toast Vant安装和使用

Vant 是一个VUE 的移动端组件库&#xff0c;里面有很多好用的组件。 第一步&#xff0c;安装和配置 Vant npm i vant -S npm i babel-plugin-import -D 安装完成之后&#xff0c;在项目 .babelrc 文件修改配置 plugins "plugins": [["import", {"…

15-5重构_重构-糟糕,我一直在向后做。

15-5重构by Justin Fuller贾斯汀富勒(Justin Fuller) 重构-糟糕&#xff0c;我一直在向后做。 (Refactoring — oops, I’ve been doing it backwards.) Welcome to my intervention. I’m a refactoring addict and I’m not afraid to admit it, but there’s only one prob…

JPush 使用教程

JPush 使用教程 自己使用的一些经验&#xff0c;为了方便直接从这里复制过去就行。 就当做个笔记&#xff0c;防止长时间忘记之后&#xff0c;还需要去官网看文档。 主要思路&#xff1a; sdk文件 三方依赖系统库 头文件 添加代理 初始化代码 1.版本信息 JPush : 2.2.0 Xco…

浏览器常见兼容性问题汇总

1、随便写几个标签&#xff0c;不加样式控制的情况下&#xff0c;各自的margin 和padding差异较大&#xff0c;解决方案是&#xff1a;*{margin:0;padding:0;} 2、块属性标签float后&#xff0c;又有横行的margin情况下&#xff0c;在IE6显示margin比设置的大&#xff0c;常出现…

VUE 动态绑定class

第一种&#xff1a;通过一个布尔值判断样式类是否生效 //isActive 是在data里面布尔值&#xff0c; rotateRight 是 class 样式类 //isActive 为true时样式类 rotateRight 生效 <div :class"{rotateRight:isActive}">abs</div> 第二种&#xff1a;通…

低声教育_我内心低声说:“成为建设者”

低声教育by Rebecca Radding由丽贝卡拉丁(Rebecca Radding) 我内心低声说&#xff1a;“成为建设者” (Something within me whispered: “Be the builder”) 加沙代码学院前任主持人Yasmin Hillis(自称嬉皮士)是一个内心的嬉皮士&#xff0c;她谈到了弗吉尼亚伍尔夫如何激发她…

【Web API系列教程】1.2 — Web API 2中的Action Results

前言 本节的主题是ASP.NET Web API怎样将控制器动作的返回值转换成HTTP的响应消息。 Web API控制器动作能够返回下列的不论什么值&#xff1a; 1。 void 2。 HttpResponseMessage 3&#xff0c; IHttpActionResult 4&#xff0c; Some other type 取决于返回的以上哪一种。…

前端开发常用单词

methods 方法 mounted 创建完成 export 输出 default 默认的 install 安装 components 组件 template 模板 params 参数 route 路线;途径 package 包;盒子;袋 ; toutes 路由器 plugin 插件 local host 本地 require 需要;依赖; storage 储存 prototype 原型 …

原生ajax的post操作

xml.open(方法&#xff0c;路径&#xff0c;是否开启异步)&#xff1b; console.log(e);来找出数据所在位置&#xff1b; 调用 ajax只能传二进制或字符串&#xff0c;需要先把json转一下&#xff0c;JSON.stringify()&#xff1b; 获取到数据时我们要通过JSON.parse()再转成JSO…

jquery后学什么_我在训练营两年后学到了什么

jquery后学什么by Kara Luton卡拉卢顿(Kara Luton) 我在训练营两年后学到了什么 (What I’ve Learned Two Years Post-Bootcamp) It’s been two entire years since I left behind my career of being a music publicist — one I worked towards all of college and miracul…

ExecutorService 的理解与使用

接口 Java.util.concurrent.ExecutorService 表述了异步执行的机制&#xff0c;并且可以让任务在后台执行。壹個 ExecutorService 实例因此特别像壹個线程池。事实上&#xff0c;在 java.util.concurrent 包中的 ExecutorService 的实现就是壹個线程池的实现。 ExecutorService…

前后端交互,网络请求

这边文章主要根据我自己的前端开发工作经验&#xff0c;东拼西凑出来的一点理解&#xff0c;希望能够对大家有点帮助&#xff0c;如果有误导或者错误的地方还请帮助指正&#xff0c;感谢&#xff01;&#xff01;&#xff01; 前后端交互我理解主要分为三个主要的部分&#xf…

HDU 1877 另一个版本 A+B

另一个版本 AB Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12894 Accepted Submission(s): 4901Problem Description输入两个不超过整型定义的非负10进制整数A和B(<231-1)。输出AB的m (1 < m <10…

gatsby_如何使用Gatsby.js来获取内容

gatsbyby Dimitri Ivashchuk由Dimitri Ivashchuk 如何使用Gatsby.js来获取内容 (How to source content with Gatsby.js) Gatsby.js is a powerful static site generator (with dynamic capabilities) which can be used to build super performant web-sites. It has a very…