2020牛客暑期多校训练营(第三场)

根据难度排序。
个人总结向。
如果有什么讲的不清楚的欢迎留言私信交流~

L. Problem L is the Only Lovely Problem(签到)

题意: 判断字符串是否有 lovely 开头。

思路: 模拟

代码:

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define eps 1e-10
using namespace std;

const int manx=1e6+5;
const int N=5e3+5;
//const int mod=1e9+7;
const int mod=998244353;
const ull mo=233;

int main(){
    string s; cin>>s;
    for(int i=0;i<s.size();i++) s[i]=tolower(s[i]);
    if(s.size()>=6){
        if(s.substr(0,6)=="lovely") cout<<"lovely"<<endl;
        else cout<<"ugly"<<endl;
    }else cout<<"ugly"<<endl;
    return 0;
}

B. Classical String Problem(思维)

题意: 时,输出当前字符串第x个字符,时,如果 x>0,把字符串最左边的x个字符放到字符串右边,把字符串最右边个字符放到字符串左边。

思路:
8e5 的询问破灭暴力的想法。
考虑字符串无论怎么变化,始终是一个环。
参考双向队列求长度的取模操作即可。

代码:

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define eps 1e-10
#define io std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int manx=2e6+5;
const int N=5e3+5;
//const int mod=1e9+7;
const int mod=998244353;
const ull mo=233;

char s[manx];
char c[5];
int main(){
    scanf("%s",s); ll n=strlen(s);
    ll p; scanf("%lld",&p); ll q=0;
    while(p--){
        ll x; scanf("%s%lld",c,&x);
        if(c[0]=='A')  printf("%c\n",s[(x+q-1)%n]);
        else {
            q+=x;
            q=(q+n)%n;
        }
    }
    return 0;
}

C. Operation Love(计算几何)

题意: 给出20个二维平面的点,可能是浮点数,但是顺序或者倒序连接之后一定是图中左手或者右手的图案,判断给出的图像是左手还是右手?

思路:
队友一发过太顶了。
判断最长两条边的位置。

代码:

#include <bits/stdc++.h>
#define inf 1000000009
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
#define MP std::make_pair
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
struct P
{
    double x,y;
};
P a[25];
double le(P a,P b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(P a,P b)
{
    if(a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    int t;read(t);
    while(t--){
        for(int i=1;i<=20;i++){
            cin>>a[i].x>>a[i].y;
        }
        P b[2];
        int temp=0;
        for(int i=1;i<=20&&!temp;i++){
            for(int j=i+1;j<=20;j++){
                if(abs(le(a[i],a[j])-9)<=0.00001){
                    b[1].x=a[i].x,b[0].x=a[j].x;
                    b[1].y=a[i].y,b[0].y=a[j].y;
                    temp=1;
                    break;
                }
            }
        }
        sort(b,b+2,cmp);
        //cout<<b[0].x<<" "<<b[0].y<<endl;
        //cout<<b[1].x<<" "<<b[1].y<<endl;
        temp=3;
        P c;
        for(int i=1;i<=20&&temp==3;i++){
            if(abs(le(b[0],a[i])-sqrt(145))<=0.0001){
                temp=1;
                c.x=a[i].x,c.y=a[i].y;
            }
        }
        for(int i=1;i<=20&&temp==3;i++){
            if(abs(le(b[1],a[i])-sqrt(145))<=0.0001){
                temp=0;
                c.x=a[i].x,c.y=a[i].y;
            }
        }
        //cout<<temp<<" "<<c.x<<" "<<c.y<<endl;
        if(b[0].y>b[1].y){
            if(temp==0){
                if(c.x>b[0].x) cout<<"left"<<endl;
                else cout<<"right"<<endl;
            }
            else{
                if(c.x>b[1].x) cout<<"right"<<endl;
                else cout<<"left"<<endl;
            }
        }
        else if(b[0].y<b[1].y){
            if(temp==1){
                if(c.x<b[1].x) cout<<"right"<<endl;
                else cout<<"left"<<endl;
            }
            else{
                if(c.x>b[0].x) cout<<"right"<<endl;
                else cout<<"left"<<endl;
            }
        }
        else{
            if(temp==0){
                if(c.y<b[0].y) cout<<"right"<<endl;
                else cout<<"left"<<endl;
            }
            else{
                if(c.y>b[0].y) cout<<"right"<<endl;
                else cout<<"left"<<endl;
            }
        }
    }
    return 0;
}

A、Clam and Fish(贪心)

题意:
0代表的没鱼没蚯蚓
1代表的没鱼有蚯蚓
2代表的有鱼没蚯蚓
3代表的有鱼有蚯蚓
求最多能得到多少条鱼。

思路:
有鱼钓鱼,没鱼就做鱼饵。
最后加上剩下的鱼饵的一半,即贪心取最后一半的鱼饵,另外一半钓鱼。

代码:

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define eps 1e-10
#define io std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int manx=2e6+5;
const int N=5e3+5;
const int mod=1e9+7;


int main(){
    io; ll p; cin>>p;
    while(p--){
        ll cnt=0,ans=0,n; string s; cin>>n>>s;
        for(auto x: s){
            if(x=='0'&&cnt) ans++,--cnt;
            if(x=='1') ++cnt;
            if(x=='3'||x=='2') ++ans;
        }
        ans+=cnt/2;
        cout<<ans<<endl;
    }
    return 0;
}
全部评论

相关推荐

小厂面经,也是我的处女面(30min)1.自我介绍2.spring&nbsp;boot的自动装配原理(好多类和接口的单词都忘了全称是啥了,就说了记得的单词,流程应该说对了吧)3.有用过redis吗?主要是用在实现什么功能(说了技术派用redis的zset来实现排行榜)5.有了解过Redisson吗?讲一下对于分布式锁的了解以及在什么场景下应用(说了秒杀场景)6.对mysql有了解吗?包括它的索引优化和创建(把想起来的全说了)7.了解设计模式吗?比如单例模式,为什么要使用单例模式,它的优点是什么(昨天刚看的设计模式)8.工厂模式有了解吗?主要的使用场景是?(也是昨天刚看的)9.场景题:有7个服务器,需要在早上十点定时的向数据库中的用户表中的用户发短信,如果做到发送的消息不重复,且如果发送失败了需要知道是到哪个用户失败了,这样下次就直接从这个用户开始(我答了用spring&nbsp;task来实现定时,用分布式锁来保证只有一份服务器可以发送消息,用消息队列来存储消息,然后用消息确认机制来保证错误信息的记录,以及在数据库或者业务层面完成消息消费的幂等性)10.场景题:如果在系统启动的时间就将数据库的所有用户相关的信息都读到一个hashmap中(这个没啥思路,没答好)27届的投了一个星期终于有一个面试了,大部分公司都只招26的
inari233:已oc,拒了
查看9道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务