当前位置:网站首页>2022暑假牛客多校联赛第一场
2022暑假牛客多校联赛第一场
2022-08-03 04:43:00 【胡 耀文】
签到题
A 区间合并
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
typedef pair<int,int>PII;
PII a[N];
#define l first
#define r second
int n,x,r,ans;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>x>>r;
a[i]={
x-r,x+r};
}
sort(a+1,a+1+n);
int l=a[1].l,r=a[1].r;
for(int i=2;i<=n;i++){
if(a[i].l>r)ans+=a[i].l-r;
r=max(r,a[i].r);
}
cout<<ans;
}
G
#include<bits/stdc++.h>
using namespace std;
string x;
signed main(){
cin>>x;
int n=x.size();
if(n==1){
cout<<x;
return 0;
}
int ok=1;
int cnt=0;
for(int i=0;i<n;i++){
if(x[i]=='9'){
cnt++;
continue;
}
ok=0;
}
if(cnt==n-1&&x[n-1]!='9'){
cout<<x;
return 0;
}
for(int i=1;i<n+ok;i++){
cout<<"9";
}
}
D 几何
#include<bits/stdc++.h>
using namespace std;
const double PI=acos(-1);
double x,y,r,d;
signed main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%lf %lf %lf %lf",&r,&x,&y,&d);
double b=sqrt(x*x+y*y);
if(d<=b){
printf("%.8lf\n",r*(PI/2-acos((b+d)/r)-asin((b-d)/r)));
}
else{
printf("%.8lf\n",r*(PI-acos((d-b)/r)-acos((d+b)/r)));
}
}
}
中等
I 概率dp
期望=代价+可转化状态1×转化为状态1的概率+可转化状态2×转化为状态2的概率
设dp[i][j]表示手持i张单牌,牌库还剩j张时的期望
看了下面的代码你可能会有疑问为什么i=1的时候式子是这样的
其实一点也没问题,因为3/j*dp[0][j]这个东东里面,dp[0][j]是边界状态,数值为0,你也可以先预处理
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int f[200][200],T;
string x;
int cal(string x){
set<string>S;
for(int i=1;i<26;i+=2){
string t="";
t+=x[i-1];
t+=x[i];
S.insert(t);
}
return 2*S.size()-13;
}
int qpow(int a,int b){
int ans=1;
while(b){
if(b&1)ans=(ans*a)%mod;
b/=2;
a=(a*a)%mod;
}
return ans;
}
int inv(int i,int j){
return i*qpow(j,mod-2)%mod;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
for(int i=1;i<=13;i+=2){
for(int j=3;j<=123;j++){
if(i*3>j)continue;
if(i==1)f[i][j]=(1+inv(j-3,j)*f[i][j-1])%mod;
else f[i][j]=(1+inv(3*i,j)*f[i-2][j-1]%mod+inv(j-3*i,j)*f[i][j-1])%mod;
}
}
cin>>T;
for(int id=1;id<=T;id++){
cin>>x;
int t=cal(x);
printf("Case #%lld: %lld\n",id,f[t][123]);
}
}
也可以设i为pair对,j为总牌数
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int f[200][200],T;
string x;
int cal(string x){
set<string>S;
for(int i=1;i<26;i+=2){
string t="";
t+=x[i-1];
t+=x[i];
S.insert(t);
}
return 13-S.size();
}
int qpow(int a,int b){
int ans=1;
while(b){
if(b&1)ans=(ans*a)%mod;
b/=2;
a=(a*a)%mod;
}
return ans;
}
int inv(int i,int j){
return i*qpow(j,mod-2)%mod;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
for(int i=6;i>=0;i--){
for(int j=1;j<=123;j++){
int k=13-2*i;
if(k*3>j)continue;
f[i][j]=1+inv(3*k,j)*f[i+1][j-1]%mod+inv(j-3*k,j)*f[i][j-1]%mod;
f[i][j]%=mod;
}
}
cin>>T;
for(int id=1;id<=T;id++){
cin>>x;
int t=cal(x);
printf("Case #%lld: %lld\n",id,f[t][123]);
}
}
补题:
https://ac.nowcoder.com/acm/problem/15532
边栏推荐
猜你喜欢
数字化时代,企业如何建立自身的云平台与商业模式的选择?
【Harmony OS】【ARK UI】ETS 上下文基本操作
I ported GuiLite to STM32F4 board
typescript40-class类的保护修饰符
如何利用 Flutter 实现炫酷的 3D 卡片和帅气的 360° 展示效果
typescript44-对象之间的类兼容器
接口管理工具YApi怎么用?颜值高、易管理、超好用
常见荧光染料修饰多种基团及其激发和发射波长数据一览数据
Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?
Bubble sort in c language structure
随机推荐
User password encryption tool
typescript43-类型兼容性说明
接口测试实战| GET/POST 请求区别详解
[Harmony OS] [ARK UI] ETS context basic operations
打破传统电商格局,新型社交电商到底有什么优点?
私域流量引流方法?分享购火爆的商业模式,你值得拥有
Kotlin-Flow常用封装类:StateFlow的使用
在竞争白热化的电商行业,链动2+1为什么还有企业在用
【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
install ambari
Interface test Mock combat (2) | Combined with jq to complete batch manual Mock
社交电商:链动2+1模式,为什么能在电商行业生存那么久?
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
online test paper concept
【 Harmony OS 】 【 ano UI 】 lightweight data storage
在线密码生成工具推荐
接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
Flink状态
[Fine talk] Using native js to implement todolist
BIOTIN ALKYNE CAS: 773888-45-2 Price, Supplier