*TEST 2 for NOIP 妈的智障

头更更大

这个10月完就要去搞NOIP了。。。

10月30天也就3次测试。。。为保佑进省一我还是每次测试玩都写个总结。。


boomshakalaka。。。全部写炸x2。。。
补发的基础题智障不解释,最气的是昨晚刚刚(碰巧)做的T1T3总共才得了90分??????
这里写图片描述

妈的智障

TEST 2 for NOIP(90/300)

Ball(30/100)

题目背景
SOURCE:NOIP2015-SHY-9

题目描述
Alice 与 Bob 在玩游戏。他们一共玩了 t 轮游戏。游戏中,他们分别获得了 n 个和 m 个小球。每个球上有一个分数。每个人的得分都为他所获得所有小球分数的乘积,分数小者获胜。问每轮游戏谁会获胜?请输出每轮游戏的胜者。数据保证不会出现平局,且两个人分数差异大于任意一个人分数的 1% 。

输入格式
第一行为两人玩的轮数 t(1≤t≤10)。
每一轮游戏的输入中:
第一行一个整数 n,代表 Alice 获得球的个数。
第二行为 n 个整数 ai,代表 Alice 每个球的分数。
第三行一个整数 m,代表 Bob 获得球的个数。
第四行为 m 个整数 bi,代表 Bob 每个球的分数。

输出格式
输出共 t 行,每行为该轮胜者的名字“Alice”或“Bob”。

样例数据 1
输入  [复制]

1
3
2 3 4
4
1 3 4 5
输出

Alice
备注
【样例说明】
Alice:2 * 3 * 4 = 24
Bob: 1 * 3 * 4 * 5 = 60

【数据范围】
对于 40% 的数据:n,m,ai,bi≤10;
对于 100% 的数据:1≤n,m≤100000;-10000≤ai,bi≤10000。

MY.CPP

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

const int kkk=100050;

int t,n,m,x;
int a[kkk],fa,ia;
int b[kkk],fb,ib;
int flag[2],hash[2][kkk];
long double jud;

int judge1()
{
    if(flag[0]&&fb%2==0){cout<<"Bob"<<endl;return true;}
    if(flag[0]&&fb%2==1){cout<<"Alice"<<endl;return true;}
    if(flag[1]&&fa%2==0){cout<<"Bob"<<endl;return true;}
    if(flag[1]&&fa%2==1){cout<<"Alice"<<endl;return true;}
    if(fa%2==0&&fb%2==1){cout<<"Bob"<<endl;return true;}
    if(fa%2==1&&fb%2==0){cout<<"Alice"<<endl;return true;}
    return false;
}

void judge2()
{
    if(jud<1&&fa%2==0){cout<<"Alice"<<endl;}
    if(jud>1&&fa%2==0){cout<<"Bob"<<endl;}
    if(jud<1&&fa%2==1){cout<<"Bob"<<endl;}
    if(jud>1&&fa%2==1){cout<<"Alice"<<endl;}
}

int main()
{

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> t;
    while(t--)
    {
        fa=0;fb=0;jud=1.0;ia=0;ib=0;
        memset(flag,0,sizeof(flag));
        memset(hash,0,sizeof(hash));

        cin >> n;
        for(int i=1;i<=n;i++)
        {
            cin >> x;
            if(x==0) flag[0]=1;
            if(x<0) fa++,   x=-x;
            if(hash[1][x]) hash[1][x]--;
            else hash[0][x]++;
        }
        cin >> m;
        for(int i=1;i<=m;i++)
        {
            cin >> x;
            if(x==0) flag[1]=1;
            if(x<0) fb++,   x=-x;
            if(hash[0][x]) hash[0][x]--;
            else hash[1][x]++;
        }   

        if(judge1())continue;

        while(1)
        {
            while(ia<=10000&&jud<=1e5)  
            {
                jud *= (long double)pow(ia,hash[0][ia]);
                ia+=1;
            }
            while(ib<=10000&&jud>=1e-5) 
            {
                jud /= (long double)pow(ib,hash[1][ib]);
                ib+=1;          
            }
            if(ia>10000||ib>10000) break;
        }
        //叫你不打后续代码哈哈哈哈挂了吧
        judge2();
    }
    return 0;
}

叫你不打后续代码哈哈哈哈挂了吧!
挂了吧!!
挂了吧!!!
心里痛。

STD.CPP

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

const int kkk=100050;

int t,n,m,x;
int a[kkk],fa,ia;
int b[kkk],fb,ib;
int flag[2],hash[2][kkk];
long double jud;

int judge1()
{
    if(flag[0]&&fb%2==0){cout<<"Alice"<<endl;return true;}
    if(flag[0]&&fb%2==1){cout<<"Bob"<<endl;return true;}
    if(flag[1]&&fa%2==0){cout<<"Bob"<<endl;return true;}
    if(flag[1]&&fa%2==1){cout<<"Alice"<<endl;return true;}
    if(fa%2==0&&fb%2==1){cout<<"Bob"<<endl;return true;}
    if(fa%2==1&&fb%2==0){cout<<"Alice"<<endl;return true;}
    return false;
}

void judge2()
{
    if(jud<1&&fa%2==0){cout<<"Alice"<<endl;}
    if(jud>1&&fa%2==0){cout<<"Bob"<<endl;}
    if(jud<1&&fa%2==1){cout<<"Bob"<<endl;}
    if(jud>1&&fa%2==1){cout<<"Alice"<<endl;}
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> t;
    while(t--)
    {
        fa=0;fb=0;jud=1.0;ia=0;ib=0;
        memset(flag,0,sizeof(flag));
        memset(hash,0,sizeof(hash));

        cin >> n;
        for(int i=1;i<=n;i++)
        {
            cin >> x;
            if(x==0) flag[0]=1;
            if(x<0) fa++,   x=-x;
            if(hash[1][x]) hash[1][x]--;
            else hash[0][x]++;
        }
        cin >> m;
        for(int i=1;i<=m;i++)
        {
            cin >> x;
            if(x==0) flag[1]=1;
            if(x<0) fb++,   x=-x;
            if(hash[0][x]) hash[0][x]--;
            else hash[1][x]++;
        }   

        if(judge1())continue;

        while(1)
        {
            while(ia<=10000&&jud<=1e5)  
            {
                jud *= (long double)pow(ia,hash[0][ia]);
                ia+=1;
            }
            while(ib<=10000&&jud>=1e-5) 
            {
                jud /= (long double)pow(ib,hash[1][ib]);
                ib+=1;          
            }
            if(ia>10000||ib>10000) break;
        }

        if(ia>10000)
        {
            while(ib<=10000)
            {
             jud /= pow((ib),hash[1][ib]);
             ib++;
             if(jud<1) break;
            }
        }

        if(ib>10000)
        {
            while(ia<=10000)
            {
             jud *= pow((ia),hash[0][ia]);
             ia++;
             if(jud>1) break;
            }
        }
        judge2();
    }
    return 0;
}

这是我昨晚做的自己的题解,但是有漏洞,例如你输入400个5000~9999的同一个数他会死机。

然而正解是用的log,于是比较从乘法变成了加法。
下面是正解:

真^STD.CPP

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

const int kkk=10005;

int n,m,x,t;
int fa,ia;
int fb,ib;
int flag[2];
long double jud;

int judge1()
{
    if(flag[0]&&fb%2==0){cout<<"Alice"<<endl;return true;}
    if(flag[0]&&fb%2==1){cout<<"Bob"<<endl;return true;}
    if(flag[1]&&fa%2==0){cout<<"Bob"<<endl;return true;}
    if(flag[1]&&fa%2==1){cout<<"Alice"<<endl;return true;}
    if(fa%2==0&&fb%2==1){cout<<"Bob"<<endl;return true;}
    if(fa%2==1&&fb%2==0){cout<<"Alice"<<endl;return true;}
    return false;
}

void judge2()
{
    if(jud<0&&fa%2==0){cout<<"Alice"<<endl;}
    if(jud>0&&fa%2==0){cout<<"Bob"<<endl;}
    if(jud<0&&fa%2==1){cout<<"Bob"<<endl;}
    if(jud>0&&fa%2==1){cout<<"Alice"<<endl;}
}

int main()
{
    //freopen("ball.in","r",stdin);
    //freopen("ball.out","w",stdout);   

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> t;
    while(t--)
    {
        fa=0;fb=0;jud=0;ia=0;ib=0;
        memset(flag,0,sizeof(flag));

        cin >> n;
        for(int i=1;i<=n;i++)
        {
            cin >> x;
            if(x==0) flag[0]=1;
            if(x<0) fa++,   x=-x;
            if(x!=0)jud += log(x);
        }
        cin >> m;
        for(int i=1;i<=m;i++)
        {
            cin >> x;
            if(x==0) flag[1]=1;
            if(x<0) fb++,   x=-x;
            if(x!=0)jud -= log(x);          
        }   
        if(judge1())continue;

        judge2();
    }
    return 0;
}

Array(0/100)

题目背景
SOURCE:NOIP2015-SHY-9

题目描述
给定 2 个正整数序列 A1, A2,序列长度分别为 L1, L2。
你可以进行以下的一次操作:
1. 选择两个数 K1,K2(1≤K1≤L1, 1≤K2≤L2);
2. 移去 A1 中最后 K1 个数,得到这 K1 个数的和 S1,L1 对应减少 K1;
3. 移去 A2 中最后 K2 个数,得到这 K2 个数的和 S2,L2 对应减少 K2;
此次操作的费用为:(S1-K1) * (S2-K2)。
进行以上操作直至两个序列都为空,求最小的费用总和。
注意:序列为空当且仅当两个序列同时为空。

输入格式
第一行是两个正整数 L1和 L2,表示 A1 与 A2 的长度。
第二行 L1 个整数,表示序列 A1[1..L1]。
第三行 L2 个整数,表示序列 A2[1..L2]。

输出格式
输出一个整数,表示最小费用。

样例数据 1
输入  [复制]

3 2
1 2 3
1 2
输出

2
备注
【样例说明】
第一次选取 K1=1,K2=1。费用为 (3-1)*(2-1) = 2。
第二次选取 K1=2,K2=1。费用为 (1+2-2)*(1-1) = 0。
所以,总费用为 2。

【数据范围】
对 20% 的输入数据:1≤L1,L2≤20
对 40% 的输入数据:1≤L1≤400;1≤L2≤150
对 100% 的输入数据:1≤L1,L2,A1[1..L1],A2[1..L2]≤5,000

这道题我昨晚本来想做,但是打死都没去看题解也没做出Dp来。。。
结果题解的Dp只有那么interesting了

STD.CPP

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

const int kkk=5005;

int l1,l2,a1[kkk],a2[kkk];
int f[kkk][kkk];

int main()
{    
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> l1 >> l2;
    for(int i=1;i<=l1;i++)
    {cin >> a1[i];  a1[i]=a1[i]-1;}
    for(int i=1;i<=l2;i++)
    {cin >> a2[i];  a2[i]=a2[i]-1;}

    for(int i=0;i<=l1+1;i++)
      for(int j=0;j<=l2+1;j++)
        f[i][j] = 999999999;

    f[l1+1][l2+1] = 0;
    for(int i=l1;i>=1;i--)
    for(int j=l2;j>=1;j--)
    {
        f[i][j] = min(f[i+1][j+1],min(f[i+1][j],f[i][j+1]))+a1[i]*a2[j];
    }

    cout << f[1][1];
    return 0;
}

Date

题目背景
SOURCE:NOIP2015-SHY-9

题目描述
小Y和小Z好不容易有机会相见啦,可是邪恶的小H却不想让他们相见。现在有一些城市,城市之间有双向路径相连,有路径相连的城市之间可以互相到达。小H可以任意选择一条路径,然后用他的邪恶力量污染这条路径,使得它不能被通行。虽然小Y和小Z在千辛万苦之后相遇了,但小Y非常害怕。她想让小Z告诉她,他们初始在哪些点对上,小H就可以选择一条路径污染使得他们不能相见。

注意:如果有一对点之间初始的时候就不联通,也是满足条件的,需要输出这对点。这是因为本来不联通,那么删一条边,当然也不联通。

输入格式
第一行两个数字 N 和 M 。N 表示城市数,M 表示路径数。
第二行到第 M+1 行,两个数 a 和 b。其中 1≤a,b≤N ,表示 a 和 b 之间有路径相连。

输出格式
输出一个整数,表示所求点对的数量

样例数据 1
输入  [复制]

2 1
1 2
输出

1
备注
【样例说明】
点对(1,2)满足不能相见的条件。

【数据范围】
对 30% 的输入数据 :1≤N≤100,1≤M≤200
对 100% 的输入数据 :1≤N≤20000,1≤M≤40000

。。。这道题死的只有那么冤。。。
题上说的是边有40000条然后我就真的只建了40000条边。。。
标题上线。

MY/STD.CPP

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;

const int kkk = 20050;

int n,m,val,res=0;
long long ans=0;
int first[kkk];
struct node{int u,v,val,next,flag;}side[kkk*4];//<=hamapi,hamapi

int cnt=0,top=0,tot=0,cci=1;
void addedge(int u,int v,int val)
{
    side[++cci].u = u;
    side[cci].v = v;
    side[cci].val = val;
    side[cci].flag = false;
    side[cci].next = first[u];
    first[u] = cci;
}

bool visit[kkk];
int num[kkk],intedge[kkk],outedge[kkk];
int dfn[kkk],low[kkk],belong[kkk],stk[kkk];
void tarjan(int u)
{
    low[u]=dfn[u]=++cnt;
    stk[++top]=u;   visit[u]=true;
    for(int i=first[u];i;i=side[i].next)
    {
        if(side[i].flag)continue;
        side[i].flag = true;
        side[i^1].flag = true;

        int v = side[i].v;
        if(!dfn[v]){tarjan(v);low[u]=min(low[u],low[v]);}
        else if(visit[v]){low[u]=min(low[u],dfn[v]);}
    }
    if(dfn[u]==low[u])
    {
        int v=-1;tot++;
        while(u!=v)
        {
            v=stk[top--];
            belong[v]=tot;
            num[tot]++;
            visit[v]=false;
        }
        ans -= (long long)num[tot]*(num[tot]-1)/2;
    }
}

int main()
{

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> n >> m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin >> u >> v;
        addedge(u,v,1);
        addedge(v,u,1);
    }
    ans = (long long)n*(n-1)/2;
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);

    cout << ans << endl;
    return 0;
}

感想

做一道就要对一道会一道。。。
还有审题啊hamapi
这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值