新生训练赛(3)

A - 最小的二进制数

#include <iostream>
#include <cstdio> 

using namespace std;
int n;
char a[10000];
int b[10000];
int c[10000];
int s1, s2;

int main(){
	scanf("%d", &n); 
	for (int i = 0; i < n; i ++){
		cin >> a[i];
		if (a[i] == '0') b[s1 ++] = 0;
		else c[s2 ++] = 1;
	}
	
	if (s2 == 0) printf("0");
	else{
		printf("1");
		for (int i = 0; i < s1; i ++) printf("0");
	}
	return 0;
} 

B - 线段的包含关系

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

struct node{
	int x;
	int y;
	int t;
}p[400000];

bool fff;

bool cmp(node a, node b){
	return a.y > b.y;
}

int n;

int main(){
	cin >> n;
	for (int i = 0; i < n; i ++){
		scanf("%d%d", &p[i].x, &p[i].y);
		p[i].t = i;
	}
	
	sort (p, p + n, cmp);
	
	int l = p[0].x, r = p[0].y, k = p[0].t;
	for (int i = 1; i < n; i ++){
		if (p[i].x >= l || r == p[i].y){
			if(p[i].x >= l){
				printf("%d %d", p[i].t + 1, k + 1);
			}
			else{
				if (p[i].x  < l)
				printf("%d %d", k + 1, p[i].t + 1);
				else
				printf("%d %d", p[i].t + 1, k + 1);
			}
			fff = true;
			break;
		}
		else{
			r = p[i].y;
			l = p[i].x;
			k = p[i].t;
		}
	}
	if (! fff) printf("-1 -1");
	
	return 0;
	
} 

E - 法法在分配工作

#include <iostream>
#include <cstdio> 

using namespace std;
int n;
int sum;

int main(){
	scanf("%d", &n); 
	for (int i = 1; i <= n / 2; i ++){
		int p = n - i;
		if (p % i == 0) sum ++;
	}

	printf("%d", sum);
	return 0;
} 

F - 法法要穿过大门

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n;
char a[100050];
int sum;
int x, y;

int main(){
	cin >> n;
    for (int i = 0; i < n; i ++) cin >> a[i];
    
     for(int i = 0; i < n; i ++){
       if(a[i] == 'U') y ++;
       else if(a[i]=='R') x ++;
       
       if(x == y && a[i] == a[i + 1]) sum ++;
     }
   printf("%d", sum);
   return 0; 
}

G - 法法非法是朋友


#include<iostream>
#include<cstdio>
#include<cmath> 

using namespace std;

int main(){
	double r, x1, y1, x2, y2;
    cin >> r >> x1 >> y1 >> x2 >> y2;
    double lx = x1 - x2;
    double ly = y1 - y2;
    double ld = lx * lx + ly * ly;
	
	if(ld >= r * r){
    	printf("%.16lf %.16lf %.16lf", x1, y1, r);
    	return 0;
	}
	
	if(x1 == x2 && y1 == y2){
		double rr = r / 2;
		double rx = x1 + r / 2;
		double ry = y1;
		
		printf("%.16lf %.16lf %.16lf\n", rx, ry, rr);
		return 0;
	}
	
   	double rr = (r + sqrt(ld)) / 2;
    double rx = x2 + rr * lx / sqrt(ld);
    double ry = y2 + rr * ly / sqrt(ld);
    
    printf("%.16lf %.16lf %.16lf", rx, ry, rr);
    return 0;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值