5.17 Education cf

只ac了A一道题 ,B题用了很长时间没通过。c1也没做明白,c2 都没看到。

B

You are given a string ss such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of ss such that it contains each of these three characters at least once.

A contiguous substring of string ss is a string that can be obtained from ss by removing some (possibly zero) characters from the beginning of ss and some (possibly zero) characters from the end of ss.Input

The first line contains one integer tt (1≤t≤200001≤t≤20000) — the number of test cases.

Each test case consists of one line containing the string ss (1≤|s|≤2000001≤|s|≤200000). It is guaranteed that each character of ss is either 1, 2, or 3.

The sum of lengths of all strings in all test cases does not exceed 200000200000.Output

For each test case, print one integer — the length of the shortest contiguous substring of ss containing all three types of characters at least once. If there is no such substring, print 00 instead.ExampleinputCopy

7
123
12222133333332
112233
332211
12121212
333333
31121
outputCopy

3
3
4
4
0
0
4
Note

Consider the example test:

In the first test case, the substring 123 can be used.

In the second test case, the substring 213 can be used.

In the third test case, the substring 1223 can be used.

In the fourth test case, the substring 3221 can be used.

In the fifth test case, there is no character 3 in ss.

In the sixth test case, there is no character 1 in ss.

In the seventh test case, the substring 3112 can be used.

 

题意就是在一个只含1,2,3 的字符串里找到最短的包含123的字符串,我一开始肯定会去直接想暴力的方法,

首先这个要找的字符串肯定是前后都是只有一个中间那个数字有可能是多个,就是 1+x+ 1.所以把字符串分为很多个区间,每个

新区间的标识是数字变化,然后找到每一个左右字符和自己不同的区间(符合条件的区间),并把数量记录下来。

先不说数据很大,写起来也很多很费劲,一直在找错,思路也很乱。

我去看了别人的题解,找到了好方法,这样的题可以用尺取法,取两个点 i,j  j先向前移动,当满足条件后i再向前移动。这样的确大大简化了做题。

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
 
int main(void)
{
	LL t;cin>>t;
	while(t--)
	{
		string s;
        cin>>s;
		LL a=-1;
        LL b=-1;
        LL c=-1;
		LL sum=0x3f3f3f3f;
        LL ans=0;
		for(LL i=0,j=0;i<str.size();i++)
		{
			if(str[i]=='1') a=i;
			if(str[i]=='2') b=i;
			if(str[i]=='3') c=i;
			
			if(a!=-1&&b!=-1&&c!=-1)
			{
				ans=i-(min(a,min(b,c)))+1;
				sum=min(ans,sum);
			}
		}	
		if(sum==0x3f3f3f3f)
		cout<<0<<endl;
		else 
		cout<<sum<<endl;
	}
 
return 0;
}

You are given a regular polygon with 2⋅n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n-gon.

Your task is to find the square of the minimum size such that you can embed 2n-gon in the square. Embedding 2n-gon in the square means that you need to place 2n-gon in the square in such way that each point which lies inside or on a border of 2n-gon should also lie inside or on a border of the square.

You can rotate 2n-gon and/or the square.

Input

The first line contains a single integer T (1≤T≤200) — the number of test cases.

Next T lines contain descriptions of test cases — one per line. Each line contains single even integer n(2≤n≤200). Don't forget you need to embed 2n-gon, not an n-gon.

Output

Print T real numbers — one per test case. For each test case, print the minimum length of a side of the square 2n-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed 10−6.

Example

input

3
2
4
200

output

1.000000000
2.414213562
127.321336469

题意就是 给一个n ,求每条边长都是 1 的正n边形的外接正方形面积是多少。

现在看起来还挺简单的,只不过我编程没用过三角函数,当时没用时间去做, 这题应该可以做的。

思路就是根据边的条数,求得每个等腰三角形的顶角角度,然后求底边的高,高的二倍就是 正方形的边长。即 l =1/tan(θ/2)

 

#include<bits/stdc++.h>
using namespace std;
const double PI=acos(-1.0);
const double epsilon=PI/180.0; 
void solve()
{
    int n;
    cin>>n;
    cout<<fixed<<setprecision(9)<<1.0/tan(90.0/n*epsilon)<<'\n';
}
int main()
{
   
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值