当前位置:网站首页>2022/4/22
2022/4/22
2022-04-23 04:50:00 【killer_queen4804】
排队 - 题目 - Daimayuan Online Judge 算相对顺序的方法
想了很久没有想出来,当对一个有公式的题没有思路的时候可以试一试把公式化简或展开一下,就比如这个就可以变成,前面的不会变,我们只要2ab最大就可以了,那就是让两数组的乘积最大,有一个结论是两数组有序的情况下比无序的情况乘积和更大,所以我们只要让他们相对有序就可以了,我们假定数组a是有序的,以a为准,把b离散化一下,离散化完的数组再求一遍逆序对就是答案了;但这个离散化还挺奇妙的;id这个属性就相当于离散化后的数组,c[a[i].id]=b[i].id就是以a[i].id为关键字对b[i]排序,这也算是个桶排序的思想了,之后求逆序对就可以了;我靠,这题之前做过,这在直接没印象了,不愧是我;
(7条消息) 2022-04-22每日刷题打卡_你好_Ä的博客-CSDN博客
#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
结案了,不会算概率,只要会算概率期望,这题就是一个深搜,,,
#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 算法课的加分题目
给你一个点让你算一下这个点所在连通块的周长,连通块都知道要如何去搜,关键是周长,其实不难发现只要一个X的上或下或左或右是'.'或边界就说明这个点的上或下或左或右就可以作为周长的一部分,所以周长就能算出来了,另外去搜点的时候是向八个方向搜不是四个了;
#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://blog.csdn.net/weixin_52621204/article/details/124352245
边栏推荐
- PIP3 installation requests Library - the most complete pit sorting
- Druid -- JDBC tool class case
- Sword finger offer: the path with a certain value in the binary tree (backtracking)
- Code007 -- determine whether the string in parentheses matches
- 使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
- 简单的拖拽物体到物品栏
- CLion+OpenCV identify ID number - detect ID number
- unity摄像机旋转带有滑动效果(自转)
- Unity3D 实用技巧 - 理论知识库(一)
- L2-011 play binary tree (build tree + BFS)
猜你喜欢
Simply drag objects to the item bar
C language: spoof games
Mysql50 basic exercises
【数据库】MySQL多表查询(一)
Supplement 14: cmake practice project notes (to be continued 4 / 22)
【数据库】表的查看、修改和删除
Sword finger offer: the path with a certain value in the binary tree (backtracking)
New terminal play method: script guidance independent of technology stack
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
Summary of MySQL de duplication methods
随机推荐
Innovation training (10)
js 判斷數字字符串中是否含有字符
Wechat payment function
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
PIP3 installation requests Library - the most complete pit sorting
[paper reading] [3D target detection] point transformer
MySQL time function query
COM in wine (2) -- basic code analysis
IEEE Transactions on systems, man, and Cybernetics: Notes for systems (TSMC)
Introduction to raspberry pie 3B - system installation
Druid -- JDBC tool class case
Case of using stream load to write data to Doris
PHP 统计指定文件夹下文件的数量
【数据库】MySQL单表查询
Spark optimization
unity摄像机旋转带有滑动效果(自转)
简单的拖拽物体到物品栏
POI export message list (including pictures)
C# List字段排序含有数字和字符
Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.