三连否认跪了

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;
}

然后最后有特判。。。

CF #621 div.2的更多相关文章

  1. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  2. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  3. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  4. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  5. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

  6. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组

    题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...

  7. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  8. CF#138 div 1 A. Bracket Sequence

    [#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...

  9. CF 552(div 3) E Two Teams 线段树,模拟链表

    题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有 ...

随机推荐

  1. ios--->上下拉刷新控件MJRefresh

    上下拉刷新控件MJRefresh 一.类结构 MJRefreshComponent.h MJRefreshHeader.h MJRefreshFooter.h MJRefreshAutoFooter. ...

  2. Java Email 邮件发送

    自己所编码的项目出现了问题,且是 24 小时运行于服务器上的. 如果出错了,那么我们也无从而知. 这个时候,只能通过异常捕获,然后将异常信息发送至开发者的邮箱上. 但是一个邮件的发送配置冗长,代码量至 ...

  3. Java8新特性一点通 | 回顾字符转日期&JoinArray使用

    StringToDate日期转换 Join Array使用 StringToDate日期转换 Convert string to date in ISO8601 format 利用LocalDate. ...

  4. 解决AS加载gradle时出现的Could not find com.android.tools.build:gradle:3.5.0.的错误

    时间:2019/12/7 最近在做安卓大作业时总是遇到从GitHub上下载下来的demo不能在本地Android studio中运行的问题,感觉真的被安卓中的各种版本给恶心到了,下面记录其中比较典型的 ...

  5. session、cookie、sessionStorage、localStorage的简要理解

    一.cookie和session 首先 session 和 cookie 用于浏览器客户端与服务端数据交互,通过会话的方式跟踪浏览器用户身份. 1.cookie (1).一般由服务器生成,可以设置失效 ...

  6. c++中静态成员函数

    静态成员函数 静态成函数和静态成员数据相同,他们都属于某一个类的静态成员而不是某一个对象的成员. 静态数据成员的使用方法和注意事项 1.静态数据成员在定义或说明时前面加上关键字static 2.初始化 ...

  7. 低功耗设计技术--Multi VDD--Level shifter

    本文转自:自己的微信公众号<集成电路设计及EDA教程> 前面的推文中我们分别介绍了低功耗设计中的Multi-VDD技术以及门控电源技术.在实际的低功耗设计中,门控电源技术中也常常结合Mul ...

  8. Go语言项目中使用zap日志库(翻译)

    本文先介绍了Go语言原生的日志库的使用,然后详细介绍了非常流行的Uber开源的zap日志库,同时介绍了如何搭配Lumberjack实现日志的切割和归档. 在Go语言项目中使用Uber-go的Zap L ...

  9. Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)

    题意: 给一排砖,每列的高度$a_i$,问是否可以放1*2的砖,使得n列高度一样,砖只能横着放 思路: 每两个相邻的高度相同的砖可以变成大于等于它的高度的任意高度 所以像这样的 123321 是不满足 ...

  10. Java 添加OLE对象到Excel文档

    本文介绍通过Java程序添加OLE对象到Excel文档.OLE分为两种形式,一种通过嵌入(Embed),方式,一种通过链接(Link)方式.前者是将对象嵌入到文档中,外部对该对象的更改不影响嵌入操作时 ...