Codeforces Round #368 (Div. 2)

A. Brain's Photos (Codeforces 707A)

喜闻乐见的水题,给你一张n*m的矩阵,如果只包含WGB就输出#Black&White,否则输出#Color

#include<stdio.h>
#include<string.h>
#include<math.h> 
#include<algorithm>
#define N 10005
using namespace std;
int n,m;
char s[N];
int main()
{
//    memset(a,0,sizeof(a));
    int t=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n*m;i++)
    {
        scanf(" %c",&s[i]);
        if(s[i]!='W' && s[i]!='G' && s[i]!='B')
        {
            t=1;
        }    
    }
    if(t==1)    printf("#Color\n");
    else    printf("#Black&White\n");
    return 0;
} 

 

B. Bakery (Codeforces 707B)

给定n个点,m条边,k个特殊点,要求选出一个特殊点和非特殊点,使得连接的边权最小。

若无法找到某个非特殊点与某个特殊点连通,则输出-1。

这道题感觉重点在于需要思考一下用怎样的数据结构来存点和点之间的关系。如果二维数组内存肯定爆(10^10)

因此,用u,v,l数组存点之间的关系;用st数组来存某点是否是特殊点(题中的仓库):st[i]=1该点是特殊点,st[i]=0该点不是特殊点。

则一个特殊点和非特殊点可以这样判断:

st[u[i]]+st[v[i]]==1
#include<stdio.h>
#include<string.h>
#include<math.h> 
#include<algorithm>
#define N 100005
using namespace std;
int u[N],v[N],l[N],n,m,k,st[N],ans=1e9,tt=0;
int main()
{
    memset(st,0,sizeof(st));
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u[i],&v[i],&l[i]);
    }
    for(int i=0;i<k;i++)
    {
        int x; 
        scanf("%d",&x);
        st[x]=1;
    }
    for(int i=1;i<=m;i++)
    {
        if(st[u[i]]+st[v[i]]==1)
        {
            ans=min(ans,l[i]);
            tt=1;
        }
    }
    if(tt==0)    printf("-1\n");
    else    printf("%d\n",ans);
    return 0;
} 

 

C. Pythagorean Triples  (Codeforces 707C)

数学题。给你一个数让你找出两个数使得能组成一组勾股数。没有则输出-1

公式:

1.对于大于1的奇数n=2*t+1:

x=2*t*t+2*t;
y=2*t*t+2*t+1;

2.对于大于4的偶数n=2*t:

x=t*t-1;
y=t*t+1;

3.对于4:3 5(一开始无脑公式因为这个被hack了一发,简直酸爽。也是没好好看题,以为只要找比n大的两个勾股数)

#include<stdio.h>
#include<string.h>
#include<math.h> 
#include<algorithm>
using namespace std;
long long n,x,y,t;
int main()
{
    scanf("%lld",&n);
    if(n>1 && n%2==1)
    {
        t=n/2;
        x=2*t*t+2*t;
        y=x+1;
        printf("%lld %lld\n",x,y);
    }
    else if(n>4 && n%2==0)
    {
        t=n/2;
        x=t*t-1;
        y=x+2;
        printf("%lld %lld\n",x,y);
    }    
    else if(n==4)
    {
        printf("3 5\n");
    }
    else printf("-1\n");
    return 0;
} 

 

转载于:https://www.cnblogs.com/Piddnad/p/5822943.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值