Baidu Netdisk 2020 Provincial Blue Bridge Cup question extraction code: 6666
Directory~
A: House number making
Sign-in question, the answer is 624 624624
B: Conventional score
There is nothing to say about this, double loop enumeration numerator and denominator
Calculate gcd gcdG C D can be
Answer: 2481215
C: Serpentine fill
The code is a hard simulation, once to the lower left, once to the upper right...
Answer: 761
#include <bits/stdc++.h>
using namespace std;
int a[50][50],cnt=1;
int main()
{
for(int i = 1 ; i <= 40; i++)
{
if(i % 2==1 )
{
for(int x = i, y = 1; x >= 1 && y <= i; x--, y++)
a[x][y] = cnt++;
}
else
{
for(int x = 1, y = i; x <= i && y >= 1; x++, y--)
a[x][y] = cnt++;
}
}
printf("%d\n", a[20][20]);
return 0;
}
D: Running exercise
Open a [13] a[13]a [ 1 3 ] array represents how many days in each month
Then enumerate every year, enumerate every day
It is also very simple to judge a leap year at the beginning of each year
Answer: 8879
E: Seven segment code
There are 7 77 tubes, all combinations are7! 7!7 ! kinds, so use binary enumeration ordfs dfsd f s search all possible
Then selected some points, the two adjacent points have edges
You can use union search to determine whether it is in a connected block, or you can use search to determine
Answer: 80
F: Score statistics
Nothing to say, round up and add 0.5 0.50 . . 5 intoint inti n t is fine
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n; cin >> n;
double q=0,w=0;
for(int i=1;i<=n;i++)
{
int x; cin >> x;
if( x>=60 ) q+=100;
if( x>=85 ) w+=100;
}
q/=n; w/=n;
cout << (int)(q+0.5) << "%\n";
cout << (int)(w+0.5) << "%";
}
G: palindrome date
It is still a violent enumeration every year, and the number of palindromes for that year is determined after the year is determined
For example, a certain year is abcd abcda b c d , then to form a palindrome, it must bedc dcdc月 b a ba b a heaven
So just look at whether the year does not exist on this day, remember to judge the leap year
(I started to miss the situation in the first year, now it is changed)
#include <bits/stdc++.h>
using namespace std;
int x,q,w,b[5];
int a[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool isok(int x)//判断闰年
{
if( x%400==0 ) return true;
if( x%100==0 ) return false;
if( x%4==0 ) return true;
return false;
}
int main()
{
cin >> x;
int lday = x%100, lmonth = x%10000;//天,月份
x /= 10000;//年份
for(int i=x;;i++)
{
if( isok(i) ) a[2]=29;//判断闰年
else a[2]=28;
int temp=i;
for(int j=1;j<=4;j++)//分解年份的数字
b[j]=temp%10,temp/=10;
int month=b[1]*10+b[2];//月份
int day=b[3]*10+b[4];
if( i==x && lmonth>month ) continue;//特判第一年
if( i==x && lmonth==month && lday>=day ) continue;//特判第一年
if( month>=1&&month<=12&&day>=1&&day<=a[month] )//存在这一天
{
if( q==0 ) q=i*10000+month*100+day;//最近的回文串
if( b[1]==b[3]&&b[2]==b[4] ) w= i*10000+month*100+day;//最近的AB型回文
}
if( q&&w )//都找到了
{
cout << q << "\n" << w;
return 0;
}
}
}
H: substring score sum
Violently enumerate each substring and then determine the complexity is O (n 3) O(n^3)O ( n3 ), very exaggerated
Consider enumerating each iisubstring beginning with i
Imaginary unit [i, i] [i, i][i,i ] 's contribution is1 11
We will find the smallest jjj contenta [i]! = a [j] a [i]! = a [j]a[i]!=a[j]
说明 [ i , i ] , [ i , i + 1 ] , [ i , i + 2 ] . . . . . [ i , j − 1 ] [i,i],[i,i+1],[i,i+2].....[i,j-1] [i,i],[i,i+1],[i,i+2].....[i,j−The contribution of all substrings of 1 ] is1 11
But once to [i, j] [i, j][i,j ] Contribution becomes2 22. At this time, we can find anothera [q]! = A [i] a[q]!=a[i]a[q]!=a[i]且 a [ q ] ! = a [ j ] a[q]!=a[j] a[q]!=a[j]
Then the same calculation contribution is 2 2Substring of 2
This way the jump calculation only needs to jump at most 26 262 6 times, because each letter jumps at most once
So open an id [27] [] id[27][]i d [ 2 7 ] [ ] two-dimensional array to store the subscript of each letter
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int id[27][maxn],nu[27],b[27];//下标
char a[maxn];
long long ans;
int main()
{
cin >> (a+1);
int len=strlen(a+1);
for(int i=1;i<=len;i++)
id[a[i]-'a'][++nu[a[i]-'a']]=i;//记录每个字母出现的下标
for(int i=1;i<=len;i++)//计算以i开头的子串的贡献
{
int top=0;
for(int j=0;j<=25;j++)//记录每个字母最快出现在i之后的下标
{
if( id[j][ nu[j] ] >= i )//假如出现最晚的这个字母比i大才去查找,而且需要是第一次出现
{
int index = lower_bound(id[j],id[j]+1+nu[j],i)-id[j];//二分查找加速
b[++top] = id[j][index];
}
}
sort(b+1,b+1+top);//对每个字母的出现时间排序
int last = i;
for(int j=2;j<=top;j++)
{
ans += ( b[j]-last )*(j-1) ;
last = b[j];
}
ans += ( len-last+1 )*top;
}
cout << ans;
}
I. Plane segmentation (this is the rule I found by myself, for reference only)
Draw a picture on the picture and find that if the two lines are not parallel, and there is no three-point intersection
2 4 7 11 16 22 29 37…
Just keep adding 2 22 , add3 33 , add4 44 , add5 55 , add6 66…
Suppose a point is xxIf x straight lines pass, the number of planes formed will be lessx − 1 x-1x−1 piece
If a slope has x (x >= 2) x(x>=2)x(x>=2 ) A straight line, the plane formed will be1 + 2 +... (X − 1) 1+2+...(x-1)1+2+...(x−1)
The code is not released, after all, it is just a rule.
J. String sorting
To quote a teammate: (I'm too disheveled but I didn't write it??!!)
Obviously, if the length is to be the shortest, we cannot waste every letter, so there must be letters in descending order,
To make the lexicographic order the shortest, the number of each letter must be reduced, so that’s it,
Limit the maximum number of occurrences of each letter and then dfs dfs dfs burst search,
//Author : lifehappy的垫脚石
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
char ans[N], res[N];
int n, len;
bool judge()
{
int i = len;
while(ans[i] == res[i] && i) i--;
return res[i] < ans[i];
}
void dfs(int now, int maxn, int m, int sum) {
if(sum == n)
{
if(m < len || (m == len && judge()))
{
len = m;
for(int i = 1; i <= len; i++) ans[i] = res[i];
}
return;
}
if(now >= 26) return ;
for(int i = 1; i <= maxn; i++)
{
int temp = sum + m * i;
if(temp > n) return ;
res[m + i] = char(now + 'a');
dfs(now + 1, i, m + i, temp);
}
}
int main()
{
len = 0x3f3f3f3f;
scanf("%d", &n);
dfs(0, 8, 0, 0);
for(int i = len; i >= 1; i--)
putchar(ans[i]);
return 0;
}