标签:number span tac length 字母数 iostream type trigger nbsp
前三题随便写,D题是一道dfs的水题,但当时没有找到规律,直接卡到结束
A - Kth Term /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100100 points
Print the KK-th element of the following sequence of length 3232:
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
Input is given from Standard Input in the following format:
KK
Print the KK-th element.
6
2
The 66-th element is 22.
27
5
The 2727-th element is 55.
随便写
#include <iostream> #include <cstdio> #include <cstring> #include <string.h> #include <math.h> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #define ll long long const int N=1e6+10; using namespace std; typedef pair<int,int>PII; int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; int n; int main(){ ios::sync_with_stdio(false); cin>>n; cout<<a[n-1]<<endl; return 0; }
B - Bishop /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
We have a board with HH horizontal rows and WW vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements?
Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r1r1-th row (from the top) and the c1c1-th column (from the left) to the square at the r2r2-th row and the c2c2-th column if and only if exactly one of the following holds:
For example, in the following figure, the bishop can move to any of the red squares in one move:
Input is given from Standard Input in the following format:
H WH W
Print the number of squares the bishop can reach.
4 5
10
The bishop can reach the cyan squares in the following figure:
7 3
11
The bishop can reach the cyan squares in the following figure:
1000000000 1000000000
500000000000000000
如果行是偶数,那么涂色的方格数就是 行数/2*列数,如果是奇数, 行数/2(向上取整)*列数-列数/2,因为每一列的涂色方块相差1;
#include <iostream> #include <cstdio> #include <cstring> #include <string.h> #include <math.h> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #define ll long long const int N=1e6+10; using namespace std; typedef pair<int,int>PII; ll n,m,ans; int main(){ ios::sync_with_stdio(false); cin>>n>>m; if(n==1 || m==1) ans=1; else if(n%2==0) ans=((n+1)/2)*m; else ans=((n+1)/2)*m-m/2; cout<<ans<<endl; return 0; }
C - Sqrt Inequality /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300300 points
Does √a+√b<√ca+b<c hold?
Input is given from Standard Input in the following format:
a b ca b c
If √a+√b<√ca+b<c, print Yes
; otherwise, print No
.
2 3 9
No
√2+√3<√92+3<9 does not hold.
2 3 10
Yes
√2+√3<√102+3<10 holds.
没什么好说的,两边平方一下确保不会卡精度
#include <iostream> #include <cstdio> #include <cstring> #include <string.h> #include <math.h> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #define ll long long const int N=1e6+10; using namespace std; typedef pair<int,int>PII; long double a,b,c; int main(){ ios::sync_with_stdio(false); cin>>a>>b>>c; c=c-a-b; if(c<=0) cout<<"No"<<endl; else{ c=c*c/4; if(a*b<c) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
D - String Equivalence /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400400 points
In this problem, we only consider strings consisting of lowercase English letters.
Strings ss and tt are said to be isomorphic when the following conditions are satisfied:
For example, abcac
and zyxzx
are isomorphic, while abcac
and ppppp
are not.
A string ss is said to be in normal form when the following condition is satisfied:
For example, abcac
is in normal form, but zyxzx
is not since it is isomorphic to abcac
, which is lexicographically smaller than zyxzx
.
You are given an integer NN. Print all strings of length NN that are in normal form, in lexicographically ascending order.
Input is given from Standard Input in the following format:
NN
Assume that there are KK strings of length NN that are in normal form: w1,…,wKw1,…,wK in lexicographical order. Output should be in the following format:
w1w1 :: wKwK
1
a
2
aa ab
首先在纸上列一下,找出规律,直接dfs全排列,但是要注意第k位能取的字母数是前k-1字母的种类数+1;
#include <iostream> #include <cstdio> #include <cstring> #include <string.h> #include <math.h> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #define ll long long const int N=1e6+10; using namespace std; typedef pair<int,int>PII; int n; int p=0,dif=0; char s[N]; void dfs(int u){ if(u==n){ puts(s); return; } for(char i=0;i<=dif;++i){ s[p++]=i+‘a‘; int tmp=dif; if(i==dif) dif++; dfs(u+1); p--; dif=tmp; } } int main(){ ios::sync_with_stdio(false); cin>>n; dfs(0); return 0; }
Atcoder Panasonic Programming Contest 2020
标签:number span tac length 字母数 iostream type trigger nbsp
原文地址:https://www.cnblogs.com/lr599909928/p/12519631.html