Codeforces Round #367 (Div. 2) 套题

吐槽:只能说是上分好场,可惜没打,唉

A:Beru-taxi (水题,取最小值)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long LL;
int main(){
  double x,y,ret=1e9,a,b,v;
  int n;
  scanf("%lf%lf%d",&x,&y,&n);
  for(int i=0;i<n;++i){
    scanf("%lf%lf%lf",&a,&b,&v);
    ret=min(ret,sqrt((x-a)*(x-a)+(y-b)*(y-b))/v);
  }
  printf("%.10f\n",ret);
  return 0;
}

B: Interesting drink(二分下)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N = 1e5+5;
int a[N],n,m,q;
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",&a[i]);
  sort(a+1,a+1+n);
  scanf("%d",&q);
  while(q--){
    scanf("%d",&m);
    printf("%d\n",upper_bound(a+1,a+1+n,m)-a-1);
  }
  return 0;
}

C:Hard problem(简单的O(n)dp,dp[i][0/1]代表不反转或者反转,随便写写)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N = 1e5+5;
const int INF = 0x3f3f3f3f;
LL dp[N][2];
int c[N],n;
string a[N],b[N];
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",&c[i]);
  for(int i=1;i<=n;++i){
     cin>>a[i];b[i]=a[i];
     reverse(b[i].begin(),b[i].end());
  }
  memset(dp,-1,sizeof(dp));
  dp[1][1]=c[1];dp[1][0]=0;
  for(int i=2;i<=n;++i){
    if(a[i]>=a[i-1]&&dp[i-1][0]!=-1)
    dp[i][0]=dp[i-1][0];
    if(a[i]>=b[i-1]&&dp[i-1][1]!=-1){
      if(dp[i][0]==-1)dp[i][0]=dp[i-1][1];
      else dp[i][0]=min(dp[i][0],dp[i-1][1]);
    }
    if(b[i]>=a[i-1]&&dp[i-1][0]!=-1)
    dp[i][1]=dp[i-1][0]+c[i];
    if(b[i]>=b[i-1]&&dp[i-1][1]!=-1){
      if(dp[i][1]==-1)dp[i][1]=dp[i-1][1]+c[i];
      else dp[i][1]=min(dp[i][1],dp[i-1][1]+c[i]);
    }
    if(dp[i][0]==-1&&dp[i][1]==-1){
      printf("-1\n");return 0;
    }
  }
  int i=n;
  if(dp[i][0]!=-1&&dp[i][1]==-1)printf("%I64d\n",dp[i][0]);
  else if(dp[i][1]!=-1&&dp[i][0]==-1)printf("%I64d\n",dp[i][1]);
  else printf("%I64d\n",min(dp[i][0],dp[i][1]));
  return 0;
}

D:Vasiliy‘s Multiset(老题了,01字典树贪心)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N = (2e5)*30;
const int INF = 0x3f3f3f3f;
int ch[N][2],cnt[N],tot,n;
int newnode(){
  ++tot;memset(ch[tot],-1,sizeof(ch[tot]));return tot;
}
void add(int x,int t){
   int now=0;
   for(int i=29;i>=0;--i){
      int nx=(x&(1<<i))?1:0;
      if(ch[now][nx]==-1)ch[now][nx]=newnode();
      now=ch[now][nx];cnt[now]+=t;
   }
}
int ask(int x){
  int now=0,ret=0;
  for(int i=29;i>=0;--i){
    int nx=(x&(1<<i))?1:0;
    if(ch[now][nx^1]!=-1&&cnt[ch[now][nx^1]]){
       now=ch[now][nx^1];ret+=(1<<i);
    }
    else now=ch[now][nx];
  }
  return ret;
}
char op[5];
int main(){
  tot=-1;newnode();add(0,1);
  scanf("%d",&n);
  while(n--){
    int x;scanf("%s%d",op,&x);
    if(op[0]==‘+‘)add(x,1);
    else if(op[0]==‘-‘)add(x,-1);
    else printf("%d\n",ask(x));
  }
  return 0;
}

E:Working routine(十字链表暴力,如果不会的话,可以去看看dance link的实现)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N = 1e3+5;
struct Node{
  int u,d,l,r,v;
}p[N*N];
int cnt,n,m,q,mp[N][N];
int main(){
  cnt=-1;
  scanf("%d%d%d",&n,&m,&q);
  for(int i=1;i<=n;++i){
    mp[i][0]=++cnt;
  }
  for(int i=1;i<=m;++i)mp[0][i]=++cnt;
  for(int i=1;i<=n;++i){
    for(int j=1;j<=m;++j){
      ++cnt;scanf("%d",&p[cnt].v);
      mp[i][j]=cnt;
    }
  }
  for(int i=1;i<=n;++i){
    for(int j=1;j<=m;++j){
      int id=mp[i][j];
      p[id].l=mp[i][j-1];
      p[id].r=mp[i][(j+1)%(m+1)];
      p[id].u=mp[i-1][j];
      p[id].d=mp[(i+1)%(n+1)][j];
    }
  }
  for(int i=1;i<=n;++i){
    p[mp[i][0]].l=mp[i][m];
    p[mp[i][0]].r=mp[i][1];
  }
  for(int j=1;j<=m;++j){
    p[mp[0][j]].u=mp[n][j];
    p[mp[0][j]].d=mp[1][j];
  }
  while(q--){
    int x1,y1,x2,y2,h,w;
    scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&h,&w);
    int now1=mp[x1][0],now2=mp[x2][0],k1,k2;
    for(int i=1;i<=y1;++i)now1=p[now1].r;
    for(int i=1;i<=y2;++i)now2=p[now2].r;
    k1=now1,k2=now2;
    for(int i=1;i<=w;++i){
      swap(p[p[k1].u].d,p[p[k2].u].d);
      swap(p[k1].u,p[k2].u);
      if(i==w)break;
      k1=p[k1].r;k2=p[k2].r;
    }
    for(int i=1;i<=h;++i){
      swap(p[p[now1].l].r,p[p[now2].l].r);
      swap(p[now1].l,p[now2].l);
      swap(p[p[k1].r].l,p[p[k2].r].l);
      swap(p[k1].r,p[k2].r);
      if(i==h)break;
      now1=p[now1].d;now2=p[now2].d;
      k1=p[k1].d;k2=p[k2].d;
    }
    for(int i=1;i<=w;++i){
      swap(p[p[now1].d].u,p[p[now2].d].u);
      swap(p[now1].d,p[now2].d);
      now1=p[now1].r;now2=p[now2].r;
    }
  }
      for(int i=1;i<=n;++i){
    int id=p[mp[i][0]].r;
    for(int j=1;j<m;++j){
      printf("%d ",p[id].v);
      id=p[id].r;
    }
    printf("%d\n",p[id].v);
  }
  return 0;
}

时间: 2024-10-09 22:19:39

Codeforces Round #367 (Div. 2) 套题的相关文章

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱! 直接暴力求出矩阵数值,然后枚举每一个[I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了 CODE:#include <cstdio> #include <cstring>#include <queue>#include <vect

Codeforces Round #367 (Div. 2) D. Vasiliy&#39;s Multiset

题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 题解: trie树xjb搞就行,每次要贪心,尽量满足高位为1. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;i++) 3 using namespace std; 4 5 namespace trie 6 {

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov

Codeforces Round #367 (Div. 2)

A. Beru-taxi (Codeforces 706A) 水题,求一下到每个点的距离,取最小值即可 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define N using namespace std; int n,x,y,p,q,s; double t,ans=1000000000; int main() { scanf("%d%d%d&

Codeforces Round #374 (div.2)遗憾题合集

C.Journey 读错题目了...不是无向图,结果建错图了(喵第4样例是变成无向就会有环的那种图) 并且这题因为要求路径点尽可能多 其实可以规约为限定路径长的拓扑排序,不一定要用最短路做 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm>

Codeforces Round #297 (Div. 2) E题. Anya and Cubes (中途相遇法)

题目地址:Anya and Cubes 比赛的时候居然没想起中途相遇法...这题也是属于想起来就很简单系列. 中途相遇法也叫折半搜索.就是处理前一半,把结果储存起来,再处理后一半,然后匹配前一半存储的结果. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib

Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. 首先我们根据一个维度(c维)对n个三元组排序,然后枚举答案在这个维度的取值. 此时序列被分成了两个部分,前半部分 满足所有c大于等于i 后半部分满足所有c严格小于i(即已有一个维度小于) 通过累计,我们知道此时前半部a维的最大值ma和b维的最大值mb. 显然可能存在的三元组答案,必然首先满足a维和