Noip 2017 最简单的三道题

A了这三道题,就可以稳拿一D了(山东)
Day1 T1
虽说是个数论题,打表出结论!

#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
    freopen("math.in","r",stdin);
    freopen("math.out","w",stdout);
    ll a,b;
    scanf("%lld%lld",&a,&b);
    if(a<b) swap(a,b);
    printf("%lld",a*(b-1)-b);
    return 0;
}

Day1 T2
很明显的是一个栈模拟,但需要很多特判,很考验代码能力。
考场上的代码很丑!

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
bool vis[200];
char s1[20000];
struct node{
    int z;
    bool ok;
    bool f;
}s[1000];
int top;
int check()
{
    bool ok=1;
    int maxi=0;
    for(int i=1;i<=top;i++)
    {
        if(ok==1&&s[i].f==1) maxi++;
        if(s[i].ok==0) ok=0;
    }
    return maxi;
}
void get_ans()
{
    memset(vis,0,sizeof(vis));
    top=0;
    int maxi=0;
    int flag1=0;
    bool f=0;
    int n,time=0;
    scanf("%d ",&n);
    //if(n%2) flag1=1;
    gets(s1);
    int len=strlen(s1);
    for(int i=0;i<len;i++)
    {
        if(s1[i]=='n') f=1;
        if(s1[i]>='0'&&s1[i]<='9'&&f)
         time=time*10+s1[i]-'0';
    }
    if(time==0) f=0;
    bool ok=1;
    for(int i=1;i<=n;i++)
    {
        gets(s1);
        int len=strlen(s1);
        if(flag1) continue;
        if(s1[0]=='E') 
        {
            if(top==0) 
            {
                flag1=1;
                continue;
            }
            maxi=max(maxi,check());
            vis[s[top--].z]=0;
            continue;
        }
        top++;
        if(vis[s1[2]-'a'+1])
        {
            flag1=1;
            continue;
        }
        vis[s1[2]-'a'+1]=1;
        s[top].z=s1[2]-'a'+1;
        int f1=0,f2=0;
        bool o1=0;
        for(int j=4;j<len;j++)
        {
            if(s1[j]=='n') 
            {
                if(f1==0) f1=200;
                else f2=200;
            }
            if(s1[j]>='0'&&s1[j]<='9')
             {
                if(o1==0) f1=f1*10+s1[j]-'0';
                else f2=f2*10+s1[j]-'0';
             }
            if(s1[j]==' ') o1=1;
        }
        if(f1==200&&f2==200)
        {
            s[top].ok=1;
            s[top].f=0;
            continue;
        }
        else
        {
            if(f1<=100&&f2==200) 
             {
                s[top].ok=1;
                s[top].f=1;
                continue;
             }
            else
             {
                if(f1>f2) s[top].ok=0,s[top].f=0;
                else s[top].ok=1,s[top].f=0;
             }
        }
    }
    if(flag1||top!=0) printf("ERR\n");
    else
    {
        if(time!=maxi) printf("No\n");
        else printf("Yes\n");
    }
    //printf("%d %d",f,time);
}
int main()
{
    //freopen("complexity.in","r",stdin);
    //freopen("complexity.out","w",stdout);
    int t;
    scanf("%d\n",&t);
    while(t--)
     get_ans();

    return 0; 
}

Day2 T1
建图+DFS 没有并查集快!

#include <cstdio>
#include <iostream>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;
const int maxm=1010*1010;
struct node{
    ll x,y,z;
}a[maxm];
int head[1010],net[2*maxm],to[2*maxm];
int cnt;
bool vis[1011];
ll jx=2;
ll get(ll a1,ll a2)
{
    ll ans=(a[a1].x-a[a2].x)*(a[a1].x-a[a2].x)+(a[a1].y-a[a2].y)*(a[a1].y-a[a2].y)+(a[a1].z-a[a2].z)*(a[a1].z-a[a2].z);
    return ans;
}
void add(int x,int y)
{
    cnt++;
    to[cnt]=y;
    net[cnt]=head[x];
    head[x]=cnt;
}
ll read()
{
    ll x=0,w=1;
    char s=0;
    while(s<'0'||s>'9') 
    {
        if(s=='-') w=-1;
        s=getchar();
    }
    while(s>='0'&&s<='9')
    {
        x=(x<<3)+(x<<1)+s-'0';
        s=getchar();
    }
    return x*w;
}
bool dfs(int x,int e)
{
    //vis[x]=1;
    if(x==e)
     return 1;
    for(int i=head[x];i;i=net[i])
    {
        int p=to[i];
        if(vis[p]) continue;
        vis[p]=1;
        bool d=dfs(p,e);
        if(d) return 1;
    }
    return 0;
}
void work()
{
    memset(a,0,sizeof(a));
    memset(head,0,sizeof(head));
    memset(net,0,sizeof(net));
    memset(to,0,sizeof(to));
    memset(vis,0,sizeof(vis));
    int flag1=1,flag2=1;
    cnt=0;
    int n;
    ll h,r;
    scanf("%d%lld%lld",&n,&h,&r);
    for(int i=1;i<=n;i++)
     a[i].x=read(),a[i].y=read(),a[i].z=read();
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
         if((jx*r*jx*r)>=get(i,j)) add(i+1,j+1),add(j+1,i+1);
        if(a[i].z-r<=0) add(1,i+1),add(i+1,1),flag1=0;
        if(a[i].z+r>=h) add(i+1,n+2),add(n+2,i+1),flag2=0;
    }
    if(flag1||flag2) 
    {
        printf("No\n");
        return;
    }
    //printf("%d %d\n",flag1,flag2);
    vis[1]=1;
    bool f=dfs(1,n+2);

    if(f) printf("Yes\n");
    else printf("No\n");

    return;
}
int main()
{
    //freopen("cheese.in","r",stdin);
    //freopen("cheese.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--)
     work();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值