当前位置:网站首页>2022/4/22
2022/4/22
2022-04-23 04:58:00 【killer_ queen4804】
line up - subject - Daimayuan Online Judge How to calculate the relative order
I haven't thought of it for a long time , When you have no idea about a problem with formula, you can try to simplify or expand the formula , For example, this can become
, The one in front won't change , All we have to do is 2ab The biggest is enough , That is to maximize the product of two arrays , One conclusion is that the product sum of two arrays in order is greater than that in disorder , So we just need to keep them relatively orderly , Let's assume that the array a Is ordered , With a Subject to , hold b Discretization , The answer is to find the inverse pair of the discretized array again ; But this discretization is wonderful ;id This property is equivalent to the discretized array ,c[a[i].id]=b[i].id That is to say a[i].id Is a keyword pair b[i] Sort , This is also a bucket sorting idea , Then find the reverse order pair ; I rely on , I've done this before , I'm not impressed at all , I am worthy of it ;
(7 Bar message ) 2022-04-22 Swipe questions and punch in every day _ Hello _Ä The blog of -CSDN Blog
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((-x)&(x))
using namespace std;
const ll inf=1e16;
const ll mod=1e8-7;
ll n;
struct node{
ll id,v;
}a[100005],b[100005],c[100005];
bool cmp(node a,node b){
return a.v<b.v;
}
bool cmp1(node a,node b){
if(a.v==b.v) return a.id>b.id;
return a.v>b.v;
}
ll t[100005];
void add(ll x){
for(int i=x;i<=n;i+=lowbit(i))
t[i]=(t[i]+1)%mod;
}
ll ask(ll x){
ll res=0;
for(int i=x;i;i-=lowbit(i))
res=(res+t[i])%mod;
return res;
}
int main(){
//freopen("in.txt","r",stdin);
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld",&a[i].v),a[i].id=i;
for(int i=1;i<=n;i++) scanf("%lld",&b[i].v),b[i].id=i;
sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp);
for(int i=1;i<=n;i++) c[a[i].id].v=b[i].id,c[a[i].id].id=a[i].id;
sort(c+1,c+n+1,cmp1);
ll ans=0;
for(int i=1;i<=n;i++){
//cout<<c[i].id<<" "<<c[i].v<<endl;
ans=(ans+ask(c[i].id-1))%mod;
add(c[i].id);
}
printf("%lld\n",ans);
return 0;
}
Problem - 839C - Codeforces
It's over , It's not a probability , As long as you can calculate the probability expectation , This question is a deep search ,,,
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((-x)&(x))
using namespace std;
const ll inf=1e16;
const ll mod=1e8-7;
ll n;
double sum;
vector<ll>v[100005];
void dfs(ll u,ll fa,double s,ll dep){
ll cnt=0;
for(int i=0;i<v[u].size();i++) if(v[u][i]!=fa) cnt++;
if(cnt==0){
sum+=(double)s*dep;
return;
}
for(int i=0;i<v[u].size();i++){
ll j=v[u][i];
if(j==fa) continue;
dfs(j,u,s*(1.0/cnt),dep+1);
}
}
int main(){
//freopen("in.txt","r",stdin);
scanf("%lld",&n);
for(int i=1;i<n;i++){
ll u,vv;
scanf("%lld%lld",&u,&vv);
v[u].push_back(vv);
v[vv].push_back(u);
}
sum=0;
dfs(1,-1,1,0);
printf("%.15f\n",sum);
return 0;
}
ZOJ (pintia.cn)1047 Bonus topic of algorithm class
Give you a point and let you calculate the perimeter of the connecting block where this point is located , All connected blocks know how to search , The key is perimeter , In fact, it is not difficult to find that only one X Up or down or left or right is '.' Or boundary means that the upper or lower, left or right of this point can be used as part of the perimeter , So the perimeter can be calculated , In addition, when you search for points, you search in eight directions, not four ;
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((-x)&(x))
using namespace std;
const ll inf=1e16;
const ll mod=1e8-7;
ll n,m,vis[30][30],cx,cy,cnt;
char a[30][30];
struct node{
ll x,y;
};
ll dx[8]={1,-1,0,0,1,1,-1,-1};
ll dy[8]={0,0,1,-1,1,-1,1,-1};
void bfs(){
queue<node>q;
q.push(node{cx,cy});
while(!q.empty()){
node u=q.front();q.pop();
ll ux=u.x,uy=u.y;
if(vis[ux][uy]) continue;
vis[ux][uy]=1;
for(int i=0;i<4;i++){
ll tx=ux+dx[i],ty=uy+dy[i];
if(tx<1||tx>n||ty<1||ty>m||a[tx][ty]=='.') cnt++;
}
for(int i=0;i<8;i++){
ll tx=ux+dx[i],ty=uy+dy[i];
if(tx<1||tx>n||ty<1||ty>m||a[tx][ty]=='.') continue;
if(a[tx][ty]=='X'&&!vis[tx][ty]) q.push(node{tx,ty});
}
}
}
int main(){
//freopen("in.txt","r",stdin);
while(scanf("%lld%lld%lld%lld",&n,&m,&cx,&cy)){
if(n==0&&m==0&&cx==0&&cy==0) break;
cnt=0;
for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++) vis[i][j]=0;
//if(a[cx][cy]=='.'){printf("0\n");continue;}
bfs();
printf("%lld\n",cnt);
}
return 0;
}
版权声明
本文为[killer_ queen4804]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230450288591.html
边栏推荐
- Use AES encryption - reuse the wisdom of predecessors
- DIY is an excel version of subnet calculator
- 多线程基本概念(并发与并行、线程与进程)和入门案例
- Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
- Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
- 信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
- 洛谷P2731骑马修栅栏
- The programmer starts the required application with one click of window bat
- 深度学习笔记 —— 语义分割和数据集
- Deep learning notes - semantic segmentation and data sets
猜你喜欢

DIY 一个 Excel 版的子网计算器

2022/4/22

AQS源码阅读

Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)

The 8 diagrams let you see the execution sequence of async / await and promise step by step

Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!

Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘

【数据库】MySQL基本操作(基操~)

Innovation training (V) configuration information

Spark small case - RDD, spark SQL
随机推荐
Deep learning notes - fine tuning
L2-011 play binary tree (build tree + BFS)
Learning Android from scratch -- Introduction
Manually write smart pointer shared_ PTR function
什么是指令周期,机器周期,和时钟周期?
MySQL -- execution process and principle of a statement
The vscode ipynb file does not have code highlighting and code completion solutions
What is the meaning of load balancing
[2021] Spatio-Temporal Graph Contrastive Learning
C. Tree Infection(模拟+贪心)
2022/4/22
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
Detailed explanation of hregionserver
AQS源码阅读
直播带货表格模板-自动显示图片-自动关联系列商品
Sword finger offer: push in and pop-up sequence of stack
【数据库】MySQL多表查询(一)
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
scp命令详解