Codeforces Round #103 (Div. 2)

A 水

#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define LL long long
#define pii pair<int ,int>
#define bug cout<<"here!!"<<endl
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF  freopen("output.txt","w",stdout)
#define eps 1e-8
#define MIN INT_MIN
#define inf 1<<30
#define N 440
#define M N*N
int a[102];
int main(){
    int n;
    cin>>n;
    int i;
    int s,t;
    int minm = inf,maxm = 0;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=minm){
            minm = a[i];
            s = i;
        }
        if(a[i] > maxm){
            maxm=  a[i];
            t = i;
        }
    }
    if(s<t)
    printf("%d\n",n-1-s+t-1);
    else printf("%d\n",n-1-s+t);
    return 0;
}
B 水
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define LL long long
#define pii pair<int ,int>
#define bug cout<<"here!!"<<endl
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF  freopen("output.txt","w",stdout)
#define eps 1e-8
#define MIN INT_MIN
#define inf 1<<30
#define N 1005
#define M N*N
int x[N],y[N],r[N];
int dis(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}
int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int n;
    cin>>n;
    int i,j;
    int cnt=0;
    for(i=0;i<n;i++){
        cin>>x[i]>>y[i]>>r[i];
    }
    int xx,yy,xxx,yyy;
    xx = min(x1,x2);
    xxx = max(x1,x2);
    yy = min(y1,y2);
    yyy = max(y1,y2);int cc=0;
    for(i=xx;i<=xxx;i++){
        for(j=yy;j<=yyy;j++){
            if(i>xx && i<xxx && j>yy&&j<yyy)continue;
            else {cc++;
                for(int k=0;k<n;k++){
                    if(dis(i,j,x[k],y[k]) <= r[k] * r[k]){
                        cnt++;
                        break;
                    }
                }
            }
        }
    }
    cout<<cc-cnt<<endl;
    return 0;
}
C 字符串
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define LL long long
#define pii pair<int ,int>
#define bug cout<<"here!!"<<endl
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF  freopen("output.txt","w",stdout)
#define eps 1e-8
#define MIN INT_MIN
#define inf 1<<30
#define N 100005
#define M N*N
char s[N];
char p[N];
int ns[30];
int np[30];
int wen;
int main(){
    cin>>s>>p;
    int i,j;
    int ls = strlen(s);
    int lp = strlen(p);
    if(lp>ls){
        printf("0\n");
        return 0;
    }wen=0;
    for(i=0;i<lp;i++){
        np[p[i] - 'a'] ++;
        if(s[i]!='?')
        ns[s[i] - 'a'] ++;
        else wen++;
    }
    int cnt=0;
    int num=0;bool ok=1;
    for(i=0;i<26;i++){
        if(ns[i] > np[i]){
            ok=0;
            break;
        }
        if(ns[i]<np[i] && np[i]>0)num+=np[i]-ns[i];
    }
    if(ok && wen == num)cnt++;
    for(i=lp;i<ls;i++){
        num = 0;ok=1;
        if(s[i-lp] == '?')wen--;
        else ns[s[i-lp]-'a']--;
        if(s[i]!='?')
        ns[s[i]-'a']++;
        else wen++;
        for(j=0;j<26;j++){
        if(ns[j] > np[j]){
            ok=0;
            break;
        }
        if(ns[j]<np[j] && np[j]>0)num+=np[j]-ns[j];
        }
    if(ok && wen == num)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
D 求出最短路后乱搞
#include<iostream>
#include<string.h>
#include<cstdio>
#include <vector>
#include <queue>
using namespace std;
#define N 100004
const int INF = (1<<30);
int n,m;
struct edge{
    int u,v,w;
    int next;
}e[N*10];
int head[N];
int dis[N];
bool vis[N];          //记录顶点是否在队列中,SPFA算法可以入队列多次
int cnt[N];             //记录顶点入队列次数
int ans;
int l;
int ecnt;
void init(){
    ecnt = 0;
    memset(head,-1,sizeof(head));
}
void add(int u,int v,int w){
    e[ecnt].u = u;
    e[ecnt].v = v;
    e[ecnt].w = w;
    e[ecnt].next = head[u];
    head[u] = ecnt++;
}
bool SPFA(int s){
    queue<int>  qq;
    int i;
    for(i=1;i<=n;++i){
        dis[i] = INF;        //将除源点以外的其余点的距离设置为无穷大
        vis[i] = 0;
        cnt[i] = 0;
    }
    dis[s]=0;              //源点的距离为0
    vis[s] = 1;
    cnt[s]++;            //源点的入队列次数增加
    qq.push(s);
    int u,v;
    while(!qq.empty()){
        u = qq.front();
        qq.pop();
        vis[u] = 0;
        for(i=head[u];i!=-1;i = e[i].next){
            v = e[i].v;
            int cost = e[i].w;
            if(dis[v] > cost+dis[u]){
                dis[v] = cost+dis[u];
                if(!vis[v]){
                    vis[v] = 1;
                    qq.push(v);
                    cnt[v]++;
                    if(cnt[v] >= n)return false;
                }
            }
        }
    }
    return true;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int s;
    scanf("%d%d%d",&n,&m,&s);
    int i;
    int a,b,w;
    init();
    for(i=0;i<m;++i){         //双向
        cin>>a>>b>>w;
        add(a,b,w);
        add(b,a,w);
     }
     cin>>l;
     ans = 0;
     SPFA(s);
     for(i=1;i<=n;i++){
         if(dis[i] == l)ans++;
     }
     for(i=0;i<ecnt;i+=2){
         int u = e[i].u;
         int v = e[i].v;
         int val = e[i].w;
         int d1 = l - dis[u];
         int d2 = l - dis[v];
         if(d1 >0 && d2 > 0){
             if(d1 + d2 == val)ans++;
             if(d1 + d2 < val)ans+=2;
         } else {
             if(d1 > 0 && d1 < val)ans++;
             if(d2 > 0 && d2 < val)ans++;
         }
     }
     cout<<ans<<endl;
     return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值