2020 牛客 多校

1.F

aa
b
zzz
zz
aba
abaa
<
=
>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s1,s2;
int main()
{
    while(cin>>s1>>s2){
        if(s1+s2==s2+s1)
        printf("=\n");
        if(s1+s2<s2+s1)
        printf("<\n");
        if(s1+s2>s2+s1)
        printf(">\n");
    }
    return 0;
}

2.Cover the tree
在这里插入图片描述
找最少的链条包括所有边

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n;
vector<int>g[N];
vector<int>ans;

void dfs(int u,int fa){
	for(int i=0;i<g[u].size();i++){
		if(g[u][i]==fa) continue;
		dfs(g[u][i],u);
	}
	if(g[u].size()==1){
		ans.push_back(u);
	}
}

int main(){
	cin>>n;
	int u,v;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		g[u].push_back(v);
        g[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		if(g[i].size()>1){
			dfs(i,0);
			break;
		}
	}
	int len=ans.size();
	int len2=(len+1)/2;
	cout<<len2<<endl;
    for(int i=0;i<len/2;i++)
        printf("%d %d\n", ans[i], ans[i+len/2]);
    if(ans.size()&1) printf("%d %d\n", ans[0], ans.back());
    return 0;
}

3.Duration

#include<stdio.h>
#include<stdlib.h>
int main(){
    int h1,m1,s1,h2,m2,s2;
    char a;
    int result;
    scanf("%d%c%d%c%d",&h1,&a,&m1,&a,&s1);
    scanf("%d%c%d%c%d",&h2,&a,&m2,&a,&s2);
    result = abs((h2-h1)*3600+(m2-m1)*60+(s2-s1));
    printf("%d\n",result);
}

4.Boundary
给几个点然后找到一个圆过原点而且包括的点最多

#include <bits/stdc++.h>
using namespace std;
typedef struct Point{
    int x, y;
}Po;

int sum=0;
typedef struct lli{
    double k,b;
    int flag;
}line;

Po p[3007];
line l[3007];
map<pair<double,double>,int> mp;
line mkline(Po a, Po b) {
    line ans;
    ans.flag=1;
    if(a.x==b.x){
        ans.k=0.0;
        ans.b=(double)(a.y+b.y)/2.0;
    }else if (a.y==b.y) {
        ans.flag=0;
        ans.k=1000007;
        ans.b=(double)(a.x + b.x)/2.0;
    } else {
        double k=(double)(b.y-a.y)*1.0/(double)(b.x - a.x);
        ans.k=-1/k;
        ans.b=(a.x+b.x)*1.0/(2*k)+(a.y+b.y)*1.0/2;
    }
    return ans;
    
};

void work(line a,line b){
	double x,y;
	if(a.flag&&b.flag){
        x=(b.b-a.b)/(a.k-b.k);
        y=a.k*x+a.b;
    }else {
        if(b.flag){
            work(b,a);
            return;
        }
        x=b.b;
        y=a.k*x+a.b;
    }
	mp[make_pair(x,y)]++;
    sum=max(sum,mp[make_pair(x,y)]);
    return ;
}
int main(){
	int n;
	cin>>n;
	Po ori;
	ori.x=0,ori.y=0;
	for(int i=0;i<n;i++){
		cin>>p[i].x>>p[i].y;
		l[i]=mkline(ori,p[i]);
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(l[i].k==l[j].k&&l[i].b==l[j].b&&l[i].flag==l[j].flag) continue;
			if(abs(l[i].k-l[j].k)<1e-6) continue;
			if(l[i].flag==0&&l[j].flag==0) continue;
			work(l[i],l[j]);
			
		}
		mp.clear();
	}
	cout<<sum+1<<endl;
}

5.Greater and greater

6 3
1 4 2 8 5 7
2 3 3
2

The two subintervals are [2,8,5],[8,5,7].

#include <bits/stdc++.h>
using namespace std;
const int N=150000+7,M=40000+7;
int n,m;
struct node{
    int x,pos;
    bool operator<(const node &t)const{
    	if(x==t.x) return pos<t.pos;
        return x<t.x;
    }
}b[M],a[N];
bitset<N> ans,tmp;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i].x);
        a[i].pos=i;
    }
    for(int i=0;i<m;i++){
        scanf("%d",&b[i].x);
        b[i].pos=i;
    }
    sort(a,a+n);
	sort(b,b+m);
	ans.set();
    tmp.set();
	int res=0;
	for(int i=0;i<m;i++){
        while(res<n&&a[res].x<b[i].x){
            tmp[a[res].pos]=0;
            res++;
        }
        ans&=(tmp>>b[i].pos);
    }
    int sum=0;
    for(int i=0;i<=n-m;i++) sum+=ans[i];
    printf("%d\n",sum);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值