20171026测试

来源:互联网 发布:仓廪实则知礼节 编辑:程序博客网 时间:2024/06/07 03:57

得分: 100 + 85 + 65

T1: copycat

题意: T组数据 每组数据两个字符串

字符串仅由小写字母,数字,空格,分号组成

可进行若干次操作后,能否将A串变为B串。可以输出1,否则输出0。

一次操作可将A串中所有小写字母x替换为小写字母y(x,y指任意小写字母)。

样例数据

输入

5
int x;
int y;
double a;
double aa;
float 1
float 2
string s;
double d;
print thisismycode;
float tooooooooooo;

输出

1
0
0
1
1

思路

可以讲A串转换为B串必须满足三个条件:

  • 两个字符串的长度相等
  • 两个字符串所有非字母位置对应相等
  • 字符串B中一个字母x出现的位置,在A串中这些位置的字母须相等
    那么根据三个条件思路就很明确了,建一个to数组就好,有点像映射
    不过考试的时候没考虑到:
    abcxyz
    zyxcba
    这种情况按照题意的话应该是不能转换的,标算考虑漏了…
#include<bits/stdc++.h>using namespace std;char s[1005],t[1005],to[30];int lens,lent,T;int main(){    //freopen("copycat.in","r",stdin);    //freopen("copycat.out","w",stdout);    scanf("%d\n",&T);    while(T--){        memset(to,0,sizeof(to));        gets(s+1);        gets(t+1);        lens=strlen(s+1);        lent=strlen(t+1);        if(lent!=lens){            putchar('0');putchar('\n');            continue;        }        int fl=1;        for(int i=1;i<=lens;++i){            if(s[i]!=t[i]){                if(s[i]<'a'||s[i]>'z'||t[i]<'a'||t[i]>'z'){ fl=0; break; }                if(!to[s[i]-'a']) to[s[i]-'a']=t[i];                else if(to[s[i]-'a']!=t[i]){ fl=0; break; }            }        }        if(!fl) putchar('0');        else putchar('1');        putchar('\n');    }    return 0;}

T2:running

题意: 给你一个无向图,每条边上有一个温度和通过时间,求从起点到终点经过的所有道路中最高温度最低的前提下,到达终点的热量最低。

第一行两个整数n,m
接下来m行四个整数a,b,t,c代表双向道路的两个端点,温度和通过所需时间

样例数据

输入

5 6
1 2 1 2
2 3 2 2
3 4 3 4
4 5 3 5
1 3 4 1
3 5 3 6
1 5

输出

3 24

按照题意,首先使通过的所有路径中最大温度最小

那么先把边按温度从小到大排序,一直加边直到起点和终点联通,即可求出最小温度

再把所有温度满足条件的边连起来,跑一次最短路即可,要注意优化常数

dijkstra算法也可以加ex数组判断,会更快一些

#include<bits/stdc++.h>using namespace std;int n,m,t,s,tot,lim;int first[500005],fa[500005];long long dis[500005];bool vis[500005];struct node{    int next,to;    long long v;}e[2000005];struct node1{    int x,y,z,c;}a[1000005];priority_queue< pair<int,int> >q;void inser(int x,int y,long long z){    tot++;    e[tot].next=first[x];    first[x]=tot;    e[tot].to=y;    e[tot].v=z;    tot++;    e[tot].next=first[y];    first[y]=tot;    e[tot].to=x;    e[tot].v=z;    return;}int read(){    int i=0,f=1;char ch=getchar();    for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') f=-1;    for(;ch<='9'&&ch>='0';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';    return i*f;}int buf[1024];inline void w(long long x){    if(!x){putchar('0');return ;}    while(x){buf[++buf[0]]=x%10;x/=10;}    while(buf[0]) putchar(buf[buf[0]--]+'0');    return;}inline bool cmp(const node1&a,const node1&b){    return a.z<b.z;}inline int find(int x){    if(fa[x]!=x) return fa[x]=find(fa[x]);    else return x;}void dij(){    q.push(make_pair(0,t));    for(int i=1;i<=n;++i) dis[i]=-1;    dis[t]=0;vis[t]=true;    while(!q.empty()){        int x=q.top().second;        q.pop();vis[x]=false;        for(int u=first[x];u;u=e[u].next){            int to=e[u].to;            if(dis[x]+e[u].v<dis[to]||dis[to]==-1){                dis[to]=dis[x]+e[u].v;                if(!vis[to]){                    vis[to]=true;                    q.push(make_pair(-dis[to],to));                }            }        }    }    return;}int main(){    n=read();m=read();    for(register int i=1;i<=n;++i) fa[i]=i;    int x,y,z,c;    for(register int i=1;i<=m;++i){        a[i].x=read();a[i].y=read();a[i].z=read();a[i].c=read();    }    t=read();s=read();    sort(a+1,a+m+1,cmp);    int fl=0;    for(register int i=1;i<=m;++i){        if(fl&&a[lim].z<a[i].z) break;        int px=find(a[i].x),py=find(a[i].y);        fa[px]=py;        lim=i;        if(!fl){            px=find(t);py=find(s);              if(px==py) fl=1;        }    }    for(register int i=1;i<=lim;++i) inser(a[i].x,a[i].y,(long long)a[i].z*a[i].c);    dij();    w(a[lim].z);putchar(' ');    w(dis[s]);    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果id锁变砖头怎么办 钥匙断在锁里了怎么办? u型锁忽然打不开怎么办 密码门锁没电了怎么办 智能门锁没电了怎么办 十字锁钥匙丢了怎么办 罐头的拉环断了怎么办 锁坏了 打不开了怎么办 门锁锁不起来了怎么办 卧室门锁舌断了怎么办 锁舌头坏了怎么办自救 门锁斜舌头断了怎么办 锁把手断了半截怎么办 门锁那一块掉了怎么办 qq动态密码忘了怎么办 小三怀孕了原配该怎么办 我当了小三怎么办 被降职后在单位怎么办 领导故意整我该怎么办 小孩怎么教育都不听怎么办 赵本山怎么办的刘涌 起诉离婚被告不出庭怎么办 安装u盘进入系统怎么办 思讯加密狗坏了怎么办 村主任选不出来怎么办 你的id已被停用怎么办 车牌摇号中签后怎么办 北京车卖了指标怎么办 车的电脑板坏了怎么办 饭卡消磁了怎么办妙招 有好项目没资金怎么办 买的股票涨停了怎么办 考研没过国家线怎么办 中石化的油卡怎么办 5173号被找回了怎么办 谭木匠梳子断了怎么办 198地块上的企业怎么办 天猫投诉不成立怎么办 顾客老嫌瓷砖贵怎么办 公司的公章丢了怎么办 物业不给充电费怎么办