WUSTACM2021-Training-1

A Very Hard Question

题目题意:就是 现在 一个橘子上涨x% y 元 (1+0.01x) 个
简单数学题 y /(1+0.01
x)

#include<cstdio>
#include<iostream>
#include<cstring>
 
using namespace std;
 
int t, n,y;
 
int main()
{
    scanf("%d", &t);
  
    while (t--)
    {
        scanf("%d%d", &y,&n);
        printf("%.0f\n", y/(1+n*0.01));
    }
    
    return 0;
}

E. The Architect Omar

字符串
寻找有多少组 2bed 1kikitchen 1*living

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
 
typedef pair<int,int>Pair;
const int N = 1010;
int t, n;
string a;
int shu[3];
 
int main()
{
    scanf("%d", &t);
 
    while (t--)
    {
        shu[0]=shu[1]=shu[2]=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            cin>>a;
            if(a[0]=='b')shu[0]++;
            if(a[0]=='k')shu[1]++;
            if(a[0]=='l')shu[2]++;
        }
        //寻找三组家具钟最小值
        int x=shu[0]/2;//bed/2
        if(x>shu[1])x=shu[1];
        if(x>shu[2])x=shu[2];
 
        printf("%d\n",x);
    }
 
    return 0;
}

K. Malek and Summer Semester

题意 给n个成绩 有多少科>=50 是不是达到了n的m%的及格率

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
 
typedef pair<int,int>Pair;
const int N = 1010;
int t, n;
int a;
float m;
 
int main()
{
    scanf("%d", &t);
 
    while (t--)
    {
        int s=0;
        scanf("%d%f",&n,&m);
        for(int i=0;i<n;i++)
        {
            cin>>a;
            if(a>=50)s++;
        }
        int o=ceil(n*1.0*m);
        if(s>=o)
        printf("YES\n");
        else printf("NO\n");
    }
   return 0;
}

H. Eyad and Math

a^b 和 c^d 比大小
两边取对数

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
 
typedef pair<int,int>Pair;
const int p = INT_MAX;
int t;
int a,b,c,d;
 
int main()
{
    scanf("%d", &t);
 
    while (t--)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
 
        if(b*log(a)-d*log(c)>0)printf(">\n");
        else printf("<\n");
    }
    return 0;
}
 

B. Linear Algebra Test

题意 寻找矩阵 n个矩阵中有多少可以 相乘的矩阵 a的列 == b的行
map映射 先用map记录其中一个矩阵行数 然后用另一矩阵列数 寻找对应映射 加起来

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
 
typedef pair<int,int>Pair;
const int N = 1e5+10;
int t,n;
int a[N][2];
 
int main()
{
    scanf("%d", &t);
 
    while (t--)
    {
        map<int,int>ma;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i][0],&a[i][1]);
            ma[a[i][0]]++;
        }
 
 
        long long s=0;
        for(int i=0;i<n;i++)
        {
            s+=ma[a[i][1]];
        }
        printf("%lld\n",s);
    }
 
    return 0;
}

F. Building Numbers
题意:一个数从1开始 有两种选择 +1 或者 *2 找到各个数的最少次数,询问l到r数组 数的次数和
分析:贪心 逆推 如果这个数是偶数 /2 一定是最快 否则 走一次 -1变偶数 直至最后倒一结束,并存入数组 并做前缀和 (询问l到r区间)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
 
typedef pair<int,int>Pair;
const int N = 1e5+100;
const int p = INT_MAX;
int t,n,q;
long long a[N];
long long d[N];
int flag;
 
void solve(long long x)
{
    if(x==1)return;
    if(x%2==0)
    {
        flag++;
        x/=2;
        solve(x);
    }
    else
    {
        flag++;
        x--;
        solve(x);
    }
}
 
int main()
{
    scanf("%d", &t);
 
    while (t--)
    {
        scanf("%d%d",&n,&q);
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
 
        for(int i=1;i<=n;i++)
        {
            flag=0;
            if(a[i])
            {
                solve(a[i]);
                d[i]=d[i-1]+flag;
            }
        }
 
        while(q--)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            printf("%lld\n",d[y]-d[x-1]);
 
        }
 
    }
 
    return 0;
}

上面就是周赛做的题

下面是补题
D. Dice Game

题意:一个骰子 每次只可以旋转90度 就是邻居的4个面可以走 从1开始抛 每转动一次 讲面的点数加入sum 求sum==x 最少次数
分析:我是最后找规律过了这个题 但是好像还有别的做法 明天再补
首先 n=1 不可能实现 必须转动
然后是1<n<11 n=7 需要三次 2 3 2才可以得到
最后 n>11 去除11的倍数 每一个实现 转一次5和6组合 最后剩的 x>0&&x<=5 需要一次转骰子 否则x>5需要转两次 加起来就是一共需要的次数

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;

typedef pair<int,int>Pair;
const int N = 1100;
int t,n;
int a[6][4]={{2,3,4,5},{1,4,5,6},{1,2,5,6},{1,3,5,6},{1,3,4,6},{2,3,4,5}};

int main()
{
    scanf("%d", &t);

    while (t--)
    {
        scanf("%d",&n);
        int s=0;
        if(n==1)printf("-1\n");
        else if(n==7)printf("3\n");//2 3 2
        else
        {
            s=n/11*2;
            int x=n%11;
            if(x<=5)s++;
            else s+=2;
            if(x==0)s--;
            printf("%d\n",s);
        }
    }

    return 0;
}

还有一种bfs的搜索寻找最少步数
sum记录每个数的步数
判定条件

  1. 不能是自己面的点数
  2. 2和5 3和4 1和6 不相邻 转不到 所以 当前面和下一面点数==7 转不了
  3. 还没有记录
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
using namespace std;

typedef pair<int,int>Pair;
struct Node{
    int up,sum,b;//当前面 目前和 步数
};
const int N = 10010;
int t,n;
int a[6][4]={{2,3,4,5},{1,4,5,6},{1,2,5,6},{1,3,5,6},{1,3,4,6},{2,3,4,5}};
int sum[N];//记录各个数和

void bfs()
{
    queue<Node>q;
    q.push(Node{1,0,0});
    memset(sum,-1,sizeof(sum));
    while(q.size())
    {
        Node x=q.front();
        q.pop();
        if(x.sum<=N)
        {
            for(int i=1;i<=6;i++)
            {
                if(x.up==i||x.up+i==7||sum[x.sum+i]!=-1)//2 5和3 4 碰不到
                    continue;

                sum[x.sum+i]=x.b+1;
                q.push(Node{i,x.sum+i,x.b+1});

            }
        }
    }
    //return sum[n];
}

int main()
{
    scanf("%d", &t);
    bfs();
    while (t--)
    {
        scanf("%d",&n);
        printf("%d\n",sum[n]);
    }

    return 0;
}

后续…

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值