CF #621 div.2

三连否认跪了

T1

开了第一题水题,一遍交过

/* make by ltao */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <string>
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define sz 666666
#define fake int
#define get() getchar()
int read(){
    int x=0;bool f=0;
    char ch=get();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=1;
        ch=get();
    }
    while(ch<='9'&&ch>='0'){
        x=(x<<1)+(x<<3)+(ch-'0');
        ch=get();
    }
    return f?-x:x;
}
char GG(){
    char ch=get();
    while(ch==' '||ch=='\r'||ch=='\n') ch=get();
    return ch;
}
using namespace std;
int t,n,d,ans,a[sz];


int main(){
//  freopen("a.in","r",stdin);
    t=read();
    while(t--){
        n=read();d=read();ans=0;
        for(int i=1;i<=n;i++) a[i]=read();  
        ans=a[1];
        for(int i=2;i<=n;i++){
            if(d>=i-1){
                int q=min(d/(i-1),a[i]);
                d-=q*(i-1);
                ans+=q; 
            }
            else break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

T2

也是·水题

/* make by ltao */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <string>
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define sz 666666
#define fake int
#define get() getchar()
int read(){
    int x=0;bool f=0;
    char ch=get();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=1;
        ch=get();
    }
    while(ch<='9'&&ch>='0'){
        x=(x<<1)+(x<<3)+(ch-'0');
        ch=get();
    }
    return f?-x:x;
}
char GG(){
    char ch=get();
    while(ch==' '||ch=='\r'||ch=='\n') ch=get();
    return ch;
}
using namespace std;
int t,n,ans,a[sz],x;


int main(){
    t=read();
    while(t--){
        n=read();x=read();int max1=0;bool flag=0;
        for(int i=1;i<=n;i++){
            a[i]=read();
            if(a[i]==x) flag=1; 
            max1=max(max1,a[i]);
        }
        if(flag){
            printf("1\n");
            continue; 
        }
        else if(max1>x)
            printf("2\n");
        else printf("%d\n",x%max1!=0?x/max1+1:x/max1);
    }
    return 0;
}

T3

我**,md有一个是算术级数的条件。。。。。。

#include <iostream>
using namespace std;

typedef long long ll;
ll arr1[26],arr2[26][26];

int main(){
  string S;
  cin>>S;
  for (int i=0;i<S.length();i++){
    int c=S[i]-'a';
    for (int j=0;j<26;j++)
      arr2[j][c]+=arr1[j];
    //就是说 arr[i][j]
    //表示 i,j 的出现数 
    arr1[c]++;
  }
  ll ans=0;
  for (int i=0;i<26;i++)
    ans=max(ans,arr1[i]);
  for (int i=0;i<26;i++)
    for (int j=0;j<26;j++)
      ans=max(ans,arr2[i][j]);
  cout<<ans<<endl;
}

但是值得一提的是,你要讨论size=1或2,因为差不固定

T4

这个题感触颇深,其实刚开始想到了分层图,然后炸了,,,,他只能跑最短的最短路。。

但是,他要你查最长的最短路。。

于是,我们可以跑一个最短路 通过枚举每条边,来做出dis1+disn+1·的最小值

值得一提的是这个排序。很神奇,他做了一个后缀的最大,把\(O(k^2)\)优化成了\(O(k)\)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int Maxn=2*1e5+111;
int dis1[Maxn],disn[Maxn],n,m,k,a[Maxn],cnt,x,y,h[Maxn];
bool vis[Maxn];
struct Edge{
    int to,lac;
    void insert(int x,int y){
        lac=h[x];
        to=y;
        h[x]=cnt++;
    }
}edge[Maxn*2];
void bfs1(){
    queue<int> q;
    q.push(1);vis[1]=1;dis1[1]=0;
    while(!q.empty()){
        int fr=q.front();q.pop();
        for(int i=h[fr];i!=-1;i=edge[i].lac){
            int to=edge[i].to;
            if(vis[to]) continue;
            dis1[to]=dis1[fr]+1;vis[to]=1;q.push(to);
        }
    }
}
void bfsn(){
    memset(vis,0,sizeof vis);
    queue<int> q;
    q.push(n);vis[n]=1;disn[n]=0;
    while(!q.empty()){
        int fr=q.front();q.pop();
        for(int i=h[fr];i!=-1;i=edge[i].lac){
            int to=edge[i].to;
            if(vis[to]) continue;
            disn[to]=disn[fr]+1;vis[to]=1;q.push(to);
        }
    }
}
bool cmp(int a,int b){
    return dis1[a]-disn[a]<dis1[b]-disn[b];
}

int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=k;i++)scanf("%d",&a[i]);
    memset(h,-1,sizeof h);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&x,&y);
        edge[cnt].insert(x,y);
        edge[cnt].insert(y,x);
    }
    bfs1();
    bfsn();
    sort(a+1,a+1+k,cmp);
    int max1=-1e7,best=0;;
    for(int i=k;i>=1;i--){
        best=max(best,max1+dis1[a[i]]);
        max1=max(max1,disn[a[i]]);
    }
    printf("%d",min(best+1,dis1[n]));
    return 0;
}

然后最后有特判。。。

猜你喜欢

转载自www.cnblogs.com/zhltao/p/12327100.html