HRBU_20211115训练

A - ^ & ^

题意:

给定a,b,当(a XOR c)&(b XOR c)为0时最小的c为多少?

做法:

异或的特点:与自身进行异或后值为0
将给定的式子进行提取公因式!
(a XOR c)&(b XOR c)=>(a & b)XOR c
因此最小的c即是a&b的结果
注意:进行位运算一定要加(a&b)再进行判断。。。不说也知道是个啥情况。Q~~Q

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+10;
int main()
{
    ios::sync_with_stdio(false);
    int t,n,ca=0;
    ll A,B;
    cin>>t;
    while(t--)
    {
        cin>>A>>B;
        if((A&B)==0)
            cout<<1<<endl;
        else
            cout<<(A&B)<<endl;
    }
    return 0;
}
/**

*/

F - Shuffle Card

题意:

给定一个长度为n的数组,数组内部的数字是有序的且唯一(这很重要!)然后在接下来m次操作中你将会数组中值为i的数字提取到数组最前面,问操作结束后数组内部数字的顺序是什么样的?

做法:

第一眼读懂题意后的第一反应,队列?但是好像不太对啊,栈?!!次次把数字提到最前面不就是把这个数字放到栈顶吗?那多余的那些数据咋处理捏?标记一下呗,输出过了就不输出了。OMO

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+10;
int main()
{
    ios::sync_with_stdio(false);
    int t,n,a[maxn],m;
    //cin>>t;
    while(cin>>n>>m)
    {
        int cnt=0;
        bool vis[maxn];
        stack<int> s;
        memset(vis,false,sizeof(vis));
        for(int i=1; i<=n; i++)
            cin>>a[i];
        for(int i=n; i>=1; i--)
            s.push(a[i]);
        while(m--)
        {
            int x;
            cin>>x;
            s.push(x);
        }
        while(!s.empty())
        {
            if(!vis[s.top()])
                cout<<s.top()<<" ",vis[s.top()]=true;
            else
                s.pop();
        }
    }
    return 0;
}
/**

*/

H - Fishing Master

题意:

你是个渔夫,你会抓鱼还会烧的一手好鱼!技多不压身,现在你的鱼塘里有n条鱼,每一条鱼都有一个烹饪时间Ti,而你抓每一条鱼花费的时间都是k,且在你抓鱼期间你啥都干不了,在你烧鱼期间你可以去抓鱼,问当你把所有的鱼都烹饪出锅需要最短的时间是多少?

做法:

嗨呀,题目已经说明了,你可以在烹饪期间去抓鱼,这就说明这里边一定有猫腻,首先,咱明确一点,第一条鱼的捕获时间和烹饪时间是一定要花费的,无可避免,从第二条鱼开始就可以开始钻时间的空档了,如果烹饪的时间相较于抓鱼时间稍微还多一点,那么这一点点时间也是可以利用的呀!积少成多嘛。核心就是优先队列处理加贪心思想啦!冲!

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+10;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    ios::sync_with_stdio(false);
    int t,n,k;
    int T[maxn];
    cin>>t;
    while(t--)
    {
        ll sum=0;
        priority_queue<int> q;
        cin>>n>>k;
        for(int i=1;i<=n;i++)
            cin>>T[i];
        sort(T+1,T+1+n,cmp);
        sum+=T[1]+k;
        q.push(T[1]%k);
        int tmp=T[1]/k,cnt=2;
        while(tmp--&&cnt<=n)
        {
            sum+=T[cnt];
            tmp+=T[cnt]/k;
            q.push(T[cnt]%k);
            ++cnt;
        }
        for(int i=cnt;i<=n;i++)
        {
            int x=q.top();
            sum+=(k-x)+T[i];
            q.pop();
            q.push(T[i]);
        }
        cout<<sum<<endl;
    }
    return 0;
}
/**

*/

G - Windows Of CCPC

题意:

第一个字符矩阵是
CC
PC
第二个是
CCCC
PCPC
PPCC
CPPC
第三个是
CCCCCCCC
PCPCPCPC
PPCCPPCC
CPPCCPPC
PPPPCCCC
CPCPPCPC
CCPPPPCC
PCCPCPPC
问第N个字符矩阵是什么样的?

做法:

每一个i(i>=2)都是由i-1个矩阵凭借而成的,分为四个部分左上↖,左下↙,右上↗,右下↘
除了左下↙部分需要进行翻转操作(P=>C,C=>P)其余部分片接即可。
核心思想:递归或者直接打表(数据量是够的呢)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+50;
char ch[maxn][maxn];

void init()
{
    ch[0][0]=ch[0][1]=ch[1][1]='C';
    ch[1][0]='P';
    ll cnt=1;
    for(int i=1;i<10;i++)
    {
        cnt=pow(2,i);
        for(int i=cnt;i<2*cnt;i++)
            for(int j=cnt;j<2*cnt;j++)
                ch[i][j]=ch[i-cnt][j-cnt];
        for(int i=0;i<cnt;i++)
            for(int j=cnt;j<2*cnt;j++)
                ch[i][j]=ch[i][j-cnt];
        for(int i=cnt;i<2*cnt;i++)
            for(int j=0;j<cnt;j++)
            {
                if(ch[i-cnt][j]=='C')
                    ch[i][j]='P';
                else
                    ch[i][j]='C';
            }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int t,k;
    init();
    cin>>t;
    while(t--)
    {
        cin>>k;
        int ans=pow(2,k);
        for(int i=0;i<ans;i++)
        {
            for(int j=0;j<ans;j++)
                cout<<ch[i][j];
            cout<<endl;
        }
    }
    return 0;
}
/**

*/

D - path

题意:

给出一张由n个点,m条边组成的带权有向图,然后会有q次询问。
每次询问需要输出第k小的路线权值和。

做法:

本蒟蒻采用的是堆+优先队列,首先明确你需要求出所有的线路权值和,en维护,划定一个四元组:u,v,w,p分别代表当前路径长度为 w w w,当前边的起点是 u u u,终点是 v v v,这条边是 u u u的出边中排序后的第 p p p条边。每次出堆的路径加入答案,然后路径向外拓展,有两种情况,一种是加入 v v v出边中最小的边,第二种是加入这条边的下一条边。最后直接输出答案即可
题解来源:传送门

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e4+10;
int n,m,q;
ll ans[maxn];
vector<pair<int,int> > G[maxn];
struct Node{
    ll w;
    int u,v,p;
    Node(ll _w,int _u,int _v,int _p):w(_w),u(_u),v(_v),p(_p) {}
    bool friend operator < (const Node &a,const Node &b){
        return a.w>b.w;
    }
};
int main()
{
    ios::sync_with_stdio(false);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&q);
        memset(ans,0,sizeof(ans));
        for(int i=1;i<=n;i++)
            G[i].clear();
        priority_queue<Node> Q;
        for(int i=1;i<=m;i++)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            G[u].push_back(make_pair(w,v));
        }
        for(int i=1;i<=n;i++)
            sort(G[i].begin(),G[i].end());
        for(int i=1;i<=n;i++)
            if(!G[i].empty())
                Q.push(Node(G[i][0].first,i,G[i][0].second,0));
        for(int i=1;i<=50000&&!Q.empty();i++)
        {
            Node now=Q.top();
            Q.pop();
            ans[i]=now.w;
            int u=now.u,v=now.v,p=now.p;
            if(G[v].size())
                Q.push(Node(now.w+G[v][0].first,v,G[v][0].second,0));
            if(p!=(int)G[u].size()-1)
                Q.push(Node(now.w+G[u][p+1].first-G[u][p].first,u,G[u][p+1].second,p+1));
        }
        while(q--)
        {
            int k;
            scanf("%d",&k);
            printf("%lld\n",ans[k]);
        }
    }
    return 0;
}
每日小结:

还差一题!!!这次真的只能明日再议了,第三次逾期了。。。罪过罪过,三个Py脚本给人处理傻了哦,即使计算器早早就写完了也还是拖到了一个小时前才完成。。。老拖延症了!得治!还意外得知自己错过了几次icpc的比赛(虽然没去真的好开心!!!OWO因为高中好哥们两个罚坐一下午O(∩_∩)O哈哈~原谅我不厚道的笑了,但是真的好恐怖啊,三道rush快的都金,吓人O ~ O)那么今日份到此结束呀!还是那句话,愿明天的朝阳能给我开心过完一天的好运!更新结束!不差了!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值