A:简单题

每次判断向上转快,还是向下转快即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define N 10005
#define ll long long
char s1[N] , s2[N]; int main()
{
// freopen("a.in" , "r" , stdin);
int n;
while(~scanf("%d" , &n))
{
scanf("%s%s" , s1 , s2);
int ans=;
for(int i= ; i<n ; i++){
int a=s1[i]-'';
int b=s2[i]-'';
if(a>b){
int t=a;
a=b;
b=t;
}
ans += min(b-a , +a-b);
}
printf("%d\n" , ans);
}
return ;
}

B:贪心

先判断所给的数中能否已经保证中位数大于y,不能的话,添加尽可能少的y使其满足中位数为y,剩下的值全定为1,判断总和是否超过x

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define N 10005
#define ll long long
int n,k,p,x,y;
int a[N];
int main()
{
// freopen("a.in" , "r" , stdin);
int n;
while(~scanf("%d%d%d%d%d" , &n,&k,&p,&x,&y))
{
int pos = (n+)/;
int cnt1 = , cnt2=;
int sum=;
for(int i= ; i<=k ; i++){
scanf("%d" , &a[i]);
if(a[i]>=y) cnt1++;
else cnt2++;
sum+=a[i];
} if(cnt1>n-pos){
for(int i=k+ ; i<=n ; i++) a[i]=,sum++;
if(sum<=x){
for(int i=k+ ; i<=n ; i++){
if(i<n) printf("%d " , a[i]);
else printf("%d\n" , a[i]);
}
}
else{
puts("-1");
}
}else{
bool flag=true;
if(pos-cnt1>n-k) flag=false;
else{
int i;
for(i=k+ ; i<=k+pos-cnt1 ; i++){
a[i] = y;
sum+=a[i];
}
for(;i<=n;i++){
a[i]=;
sum+=a[i];
}
if(sum>x) flag=false;
}
if(flag){
for(int i=k+ ; i<=n ; i++){
if(i<n) printf("%d " , a[i]);
else printf("%d\n" , a[i]);
}
}
else puts("-1");
}
}
return ;
}

C:bfs

从起点bfs,判断能否有两条路径到达终点即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define N 1005
#define ll long long
int n , m;
int dir[][] = {{,},{-,},{,},{,-}}; struct Point{
int x,y;
Point(int x= , int y=):x(x),y(y){}
}p[N][N];
int mat[N][N];
char s[N][N];
Point st , en;
queue<Point> q; bool ok(int x , int y)
{
return x> && x<=n && y> && y<=m;
} bool bfs()
{
while(!q.empty()) q.pop();
q.push(st);
while(!q.empty())
{
Point u = q.front();
q.pop();
for(int i= ; i< ; i++){
int xx = u.x+dir[i][];
int yy = u.y+dir[i][];
if(!ok(xx,yy)) continue;
if(mat[xx][yy]==){
mat[xx][yy]=-;
// cout<<"in: "<<u.x<<" "<<u.y<<" to: "<<xx<<" "<<yy<<endl;
q.push(Point(xx,yy));
}
else if(mat[xx][yy]==- && xx==en.x && yy==en.y){
// cout<<"in: "<<u.x<<" "<<u.y<<endl;
return true;
}
}
}
return false;
} int main()
{
// freopen("a.in" , "r" , stdin); while(~scanf("%d%d" , &n,&m))
{
for(int i= ; i<=n ; i++)
scanf("%s" , s[i]+);
for(int i= ; i<=n ; i++){
for(int j= ; j<=m ; j++){
if(s[i][j] == '.'){
mat[i][j]=;
}
else mat[i][j]=-;
}
} scanf("%d%d" , &st.x , &st.y);
scanf("%d%d" , &en.x , &en.y); printf("%s\n" , bfs()?"YES":"NO");
}
return ;
}

D:概率DP

dp[i][j][k] 表示剩余i个rock,j个siccsors,k个paper时的概率

初始dp[r][q][s]=1

状态转移

dp[i][j][k]+=dp[i+1][j][k]*(1.0*(i+1)*k/((i+1)*j+(i+1)*k+k*j));
dp[i][j][k]+=dp[i][j+1][k]*(1.0*(j+1)*i/(i*(j+1)+i*k+(j+1)*k));
dp[i][j][k]+=dp[i][j][k+1]*(1.0*(k+1)*j/(i*j+i*(k+1)+j*(k+1)));
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define N 210
#define ll long long double dp[N][N][N];
int r,s,q; void solve()
{
memset(dp,,sizeof(dp));
dp[r][s][q]=1.0;
for(int i=r ; i>= ; i--){
for(int j=s ; j>= ; j--){
for(int k=q ; k>= ; k--){
if(i==r && j==s && k==q) continue;
dp[i][j][k] = ;
if(k) dp[i][j][k]+=dp[i+][j][k]*(1.0*(i+)*k/((i+)*j+(i+)*k+k*j));
if(i) dp[i][j][k]+=dp[i][j+][k]*(1.0*(j+)*i/(i*(j+)+i*k+(j+)*k));
if(j) dp[i][j][k]+=dp[i][j][k+]*(1.0*(k+)*j/(i*j+i*(k+)+j*(k+)));
// cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
}
}
}
} int main()
{
// freopen("a.in" , "r" , stdin); while(~scanf("%d%d%d" , &r,&s,&q))
{
solve();
double ans1= , ans2= , ans3=;
for(int i= ; i<=r ; i++) ans1+=dp[i][][];
for(int i= ; i<=s ; i++) ans2+=dp[][i][];
for(int i= ; i<=q ; i++) ans3+=dp[][][i];
printf("%.11f %.11f %.11f\n" , ans1 , ans2 , ans3);
}
return ;
}

E:线段树

将点离散化后保存到线段树上,那么最多有200000个点

逐个添加,判断离散化的点之间可以形成多少对

在计算每个离散化的点和其他非离散化的区间内的点形成了多少对

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 200010
#define ls o<<1
#define rs o<<1|1
#define define_m int m=(l+r)>>1
#define ll long long
int a[N*] , k , p[N] , q[N] , val[N*];
ll sum[N<<];
ll ans=; int getIndex(int key)
{
return lower_bound(a , a+k , key)-a;
} void push_up(int o)
{
sum[o] = sum[ls]+sum[rs];
} void update(int o , int l , int r , int pos)
{
if(l==r && l==pos){
sum[o]++;
return ;
}
define_m;
if(m>=pos) update(ls , l , m , pos);
else update(rs , m+ , r , pos);
push_up(o);
} int query(int o , int l , int r , int s , int t)
{
if(l>r) return ;
if(l>=s && r<=t){
return sum[o];
}
int ans=;
define_m;
if(m>=s) ans+=query(ls , l , m , s , t);
if(m<t) ans+=query(rs , m+ , r , s , t);
return ans;
} int main()
{
// freopen("a.in" , "r" , stdin);
int n;
while(~scanf("%d" , &n))
{
k=;
for(int i= ; i<n ; i++){
scanf("%d%d" , &p[i] , &q[i]);
a[k++]=p[i] , a[k++]=q[i];
}
sort(a , a+k);
k = unique(a , a+k)-a;
for(int i= ; i<n ; i++){
int index = getIndex(p[i]);
val[index] = p[i];
p[i] = index;
index = getIndex(q[i]);
val[index] = q[i];
q[i]=index;
}
for(int i= ; i<n ; i++) swap(val[p[i]] , val[q[i]]);
ans = ;
memset(sum , , sizeof(sum));
for(int i= ; i<k ; i++){
int index = getIndex(val[i]);
ans += (ll)query( , , k- , index+ , k-);
update( , , k- , index);
}
//判断当前第i个点和所有非离散化区间能形成的匹配
for(int i= ; i<k ; i++){
ans += (ll)abs(val[i]-val[getIndex(val[i])]) - (ll)abs(i-getIndex(val[i]));
}
cout<<ans<<endl;
}
return ;
}
 

codeforces #301 div2的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. mysql replication错误常见处理

    大部分的错误,都是日志错误 日志本身的错误 主日志和中继日志都可能出错,可以使用mysqlbinlog来读一下mysqlbinlog mysql-bin.000007>/dev/null ##只 ...

  2. 关于c#的结构体struct与class的区别

    C# 结构体 struct C#中结构类型和类类型在语法上非常相似,他们都是一种数据结构,都可以包括数据成员和方法成员. 结构和类的区别: 1.结构是值类型,它在栈中分配空间:而类是引用类型,它在堆中 ...

  3. java只http改成https访问

    目录 生成keystore文件 修改tomcat中的server.xml文件 配置浏览器 生成keystore文件: 1.在tomcat的bin 目录下输入命令:keytool -genkeypair ...

  4. react ant design路由配置

    最初的时候,只使用了antd中的menu,header和footer都是自己写的组件,在写路由时,总是报如下错误: 相关的路由配置如下: 在网上查的说是组件未暴露出去或者是return 这一行必须有个 ...

  5. 第一章 熟悉Objective -C 编写高质量iOS与OS X代码的52 个有效方法

    第一章 熟悉Objective -C   编写高质量iOS与OS  X代码的52 个有效方法   第一条: 了解Objective-C 语言的起源 关键区别在于 :使用消息结构的语言,其运行时所应执行 ...

  6. 微信公众号:theTree20181123

    哈哈哈哈~我开通了一个微信公众号,以后的文章会发在公众号内啦~走过路过的小伙伴们过来围观一下呀~~ 主要是分为三个模块:视觉SLAM,ACM,变美树洞 这里面写下来的文章都是我再读研阶段的所学所想当然 ...

  7. python之道03

    1.有变量name = " aleX leNb " 完成如下操作: 移除 name 变量对应的值两边的空格,并输出处理结果 答案: name = " aleX leNb ...

  8. mybatis-spring_缓存

    学习之前需要先了解一下什么是mybatis一级缓存? LZ推荐:https://blog.csdn.net/niunai112/article/details/80601793#%E4%B8%80%E ...

  9. django authentication

    django authentication django session expiry login and logout view.py from django.contrib.auth import ...

  10. sleep 和wait的差别

    基本的差别 1.sleep 是Thread 类的方法,wait 是Object类中定义的方法 2.sleep()方法可以在任何地方使用 3.wait()方法只能在synchronized方法中使用,或 ...