新生赛002-补题

新生赛002

##J 新年快乐
Frog Wa has many frogs, so he can hear GuaGuaGua every day. But one day a flappy bird ate his frogs, so Frog Wa decided to build a fence to protect his precious frogs. Frog Wa told you four points (x, 0), (x, y), (z, 0), (z, t) which represent for the vertex of the fence. he want to know the area of the fence, can you tell him?
Input
The input consist of four integers x, y, z and t. 0 <= x, y, z, t <= 10000, x < z and y < t.
Output
For each test case, print the area, numbers should accurate to one decimal places.
Sample Input

1 1 2 2 
0 2 6 6
0 0 2 10

Sample Output

1.5
24.0
10.0

Hint

题意:给你四个点,求他们连成图形的面积。
思路:本题为签到题,通过画图,我们可以知道,这就是求梯形的面积。

#include<stdio.h>
int main(){
	double x,y,z,t;
	while(~scanf("%lf%lf%lf%lf",&x,&y,&z,&t)){
		printf("%.1lf\n",(y+t)*(z-x)/2);
	}
	return 0;
} 

##I-十进制中的二进制
hkhv学长最近对二进制数很感兴趣,喜欢一切0和1组成的数。现在有一个十进制整数n,问你1到n之间有多少个数是只有0和1组成的类似二进制的数,输出他们的个数。

Input
输入数据包含一个数n (1 <= n <=10^9).
Output
输出1到n中类似二进制的数的个数.
Sample Input

10

Sample Output

2

Hint

对于n = 10,1 和 10是类似二进制的数.

思路:先说我当时碰到这个题,我首先想到的是先举例,在纸上把1000以内的列了出来,企图找到规律,奈何我不是个数学大佬,做了些无用功。后来,我就打算用暴力(组长说我是太暴力),for循环求解,挨个列出来,倒是个解法,但是TME。后来就听我梁哥给我讲了讲组长的解法,非常巧妙的一个解法,首先把输进去的十进制数转成二进制数,这个二进制数就对应十进制数,让他在和原来的数n比较,大了,就退出循环

#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
ll dfs(ll x)
{
	if(x==0) return 0;
	if(x==1) return 1;
	return dfs(x>>1)*10+(x&1);//十进制转二进制
}
int main()
{
	int n;
	while(~scanf("%d",&n)){
		ll ans=1,cnt=1;
		//int flag=0;
		while(ans<=n){
			ans=dfs(cnt);
			cnt++;
		//	if(ans)
		//	flag++;
		}
		printf("%lld\n",cnt);
	}
	return 0;
}

##HA
string is called beautiful if no two consecutive characters are equal. For example, “ababcb”, “a” and “abab” are beautiful strings, while “aaaaaa”, “abaa” and “bb” are not.

Ahcl wants to construct a beautiful string. He has a string s

, consisting of only characters ‘a’, ‘b’, ‘c’ and ‘?’. Ahcl needs to replace each character ‘?’ with one of the three characters ‘a’, ‘b’ or ‘c’, such that the resulting string is beautiful. Please help him!

More formally, after replacing all characters ‘?’, the condition si≠si+1
should be satisfied for all 1≤i≤|s|−1, where |s| is the length of the string s

.

Input

The first line contains positive integer t

(1≤t≤1000) — the number of test cases. Next t

lines contain the descriptions of test cases.

Each line contains a non-empty string s

consisting of only characters ‘a’, ‘b’, ‘c’ and ‘?’.

It is guaranteed that in each test case a string s
has at least one character ‘?’. The sum of lengths of strings s in all test cases does not exceed 105

.

Output

For each test case given in the input print the answer in the following format:

If it is impossible to create a beautiful string, print “-1” (without quotes);
Otherwise, print the resulting beautiful string after replacing all ‘?’ characters. If there are multiple answers, you can print any of them.

Example
Input

3
a???cb
a??bbc
a?b?c

Output

ababcb
-1
acbac

Note
In the first test case, all possible correct answers
are “ababcb”, “abcacb”, “abcbcb”, “acabcb” and “acbacb”.
The two answers “abcbab” and “abaabc” are incorrect,
because you can replace only ‘?’ characters and the
resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4
-th and 5

-th characters will be always equal.

In the third test case, the only answer is “acbac”.
题意:就是给你一个字符串,abc自身不能靠在一起,如果有?替换为a或b或c,保证重新组成的串不能是重复的,如果根本不能组成无重复的字符串,则输出-1.
思路:对于给定的字符串,我们首先要对前面进行判断,如果首位有问号,则判断下一位为哪个字母,然后对于后面的,判断的他的前一位后一位分别是什么字母。输上一个不同的字母就行。特别的,需要注意,如果有两个相同的字母连在一块,则输出-1。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char str[100002];
int main(){
	int n;
	int len,flag;
	scanf("%d",&n);
	while(n--){
		flag=1;
		scanf("%s",str);
		len=strlen(str);
		if(str[0]=='?'){
			if(str[1]!='a') str[0]='a';               
			else if(str[1]!='b') str[0]='b';
			else if(str[1]!='c') str[0]='c';
		}
		for(int i=0;i<len;i++){
			if(str[i]=='?'){
				     if(str[i-1]!='a'&&str[i+1]!='a') str[i]='a';
				else if(str[i-1]!='b'&&str[i+1]!='b') str[i]='b';
				else if(str[i-1]!='c'&&str[i+1]!='c') str[i]='c';
			}
			else{
				if(str[i]==str[i+1]){
					flag=0;break;
				}
			}
		}
		if(flag)
		printf("%s\n",str);
		else
		printf("-1\n");
		memset(str,0,sizeof(str));
	}
	return 0;
} 

##G-0101
Alex likes to play with one and zero!One day he gets an empty string.So our cute boy wants to add one and zero in it. Every time he will add ‘01’in the string at any position and then get a new string.For example:if the string is “01” now ,he can get “0101” or “0011,Now give you a string that is Alex has get,you need to answer whether the string is legal?
Input
First is a integer n(n<=100)
Next contains n lines .Every line is a string whose legth is no more than 1000.
Output
For each case output “YES” in a single line if it’s legal.
Or you need to output “NO”;
Sample Input

3
0101
0110
0011

Sample Output

YES
NO
YES

Hint

题意:就是在01的基础上任意添加01,看看给出的串能不能由此得来。
思路:当时在比赛时理解错了,少考虑一种情况,也不能这么说其实直接就错了,看了组长的题解,以及组长在群里说了后,才明白,就是对输进去的这串数字,进行处理,从前往后判断定义一个count,如果出现了0,就+,出现了1,就-,最后判断count是不是0就可以了,另外,如果在这个过程中,count小于零,说明1在0的前面,这种情况也不符合

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
	int n,m;
	int count;
	char op[1001];
	scanf("%d",&n);
	while(n--){
		scanf("%s",op);
		m=strlen(op);
		count=0;
		for(int j=0;j<m;j++){
			if(op[j]=='0') count++;
			if(op[j]=='1') count--; 
			if(count<0) {
				count=-1;
				break;
			}
		}
		if(count)
		printf("NO\n");
		else
		printf("YES\n");
		memset(op,0,sizeof(op));
	}
	return 0;
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值