最近考试考的,好凌乱啊。。今天的周赛好碎啊。。。哎,这个感觉不太好啊、、
上来想抢fb做c结果,悲剧了啊,错了两遍才搞明白什么意思啊。。。结果感觉有点费事就放了一下,结果就卡死了啊。。没来得及再做啊。。。sad、、、
先写几道啊,其他的等到考试结束之后继续磕吧。。。
简单说一下啊:
A,比较水啊,就是给你长方体一个顶点上的三个面的面积,让你求长方体的所有边的边长。
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 100100
#define LL __int64
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
using namespace std;
int main()
{
int a, b, c;
while(cin >>a>>b>>c)
{
int x, y, z;
x = (int)sqrt(a*b/(c*1.0));
y = (int)sqrt(b*c/(a*1.0));
z = (int)sqrt(a*c/(b*1.0));
cout<<4*(x+y+z)<<endl;
}
return 0;
}
B:想复杂了啊,一直在鼓捣预处理怕超时,结果竟然这么简单,伤不起啊。。。
You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n)such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers.
Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [x, y] satisfying the property and less then m in length, such that 1 ≤ l ≤ x ≤ y ≤ r ≤ n. Note that the segment [l, r]doesn't have to be minimal in length among all segments, satisfying the given property.
The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integersa1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105).
Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
4 2 1 2 2 3
1 2
8 3 1 1 2 2 3 3 4 5
2 5
7 4 4 7 7 4 7 4 7
-1 -1
In the first sample among numbers a1 and a2 there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers.
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 1001000
#define LL __int64
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
using namespace std;
int f[M];
int dp[M];
int vi[M];
int main()
{
LL i;
LL n, k;
while(cin >>n>>k)
{
for(i = 1; i <= n; i++)
cin >>f[i];
memset(vi , 0 , sizeof(vi));
int sum = 0;
int q;
vi[f[1]] = 1;
sum = 1;
for(i = 2; i <= n; i++)
{
if(!vi[f[i]])
{
sum ++;
vi[f[i]] = 1;
}
else
{
vi[f[i]]++;
}
if(sum == k)
{
q = i;
break;
}
}
int p;
for(i = 1; i <= n; i++)
{
if(vi[f[i]] ==1)
{
p = i;
break;
}
else
vi[f[i]]--;
}
if(k == 1)
cout<<"1 1"<<endl;
else if(sum < k)
cout<<"-1 -1"<<endl;
else
cout<<p<<" "<<q<<endl;
}
return 0;
}
C题好不容易搞懂的题意,结果还是没做成功啊。。哎。。。
就是一个模拟栈的过程,求出各个自己中最多的[]的情况,然后照着原来的顺序直接输出就OK了啊。。。括号匹配啊。。
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([])" are correct (the resulting expressions are: "(1)+[1]", "([1+1]+1)"), and "](" and "[" are not. The empty string is a correct bracket sequence by definition.
A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is the string slsl + 1... sr. The empty string is a substring of any string by definition.
You are given a bracket sequence, not necessarily correct. Find its substring which is a correct bracket sequence and contains as many opening square brackets «[» as possible.
The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters.
In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.
([])
1 ([])
(((
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 1001000
#define LL __int64
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
using namespace std;
char s[M];
char str[M];
int f[M];
int vi[M];
int main()
{
int i, j, k;
while(cin >>s)
{
k = strlen(s);
memset(vi , -1 , sizeof(vi));
int top = 0;
int t = 0;
for(i = 0; i < k; i++)
{
if(s[i] == '(')
{
str[++top] = '(';
f[++t] = i;
}
else if(s[i] == ')')
{
if(str[top] == '(')
{
vi[i] = f[t];
vi[f[t]] = i;
top--;
t--;
}
else
{
str[++top] = ')';
f[++t] = i;
}
}
else if(s[i] == '[')
{
str[++top] = '[';
f[++t] = i;
}
else if(s[i] == ']')
{
if(str[top] == '[')
{
vi[i] = f[t];
vi[f[t]] = i;
top--;
t--;
}
else
{
str[++top] = ']';
f[++t] = i;
}
}
}
int x, y;
int _max = 0;
int flat1 = 0;
for(i = 0; i < k; )
{
int sum = 0;
int flat = 0;
if(vi[i]!=-1)
{
flat1 = 1;
for(j = i; vi[j]!= -1; j++)
{
if(s[j] == '[')
sum ++;
flat = 1;
}
}
if(sum > _max)
{
_max = sum;
x = i;
y = j;
}
if(flat)
i = j;
else
i++;
}
if(flat1)
{
cout<<_max<<endl;
for(i = x; i < y; i++)
cout<<s[i];
cout<<endl;
}
else
cout<<"0"<<endl;
}
return 0;
}