A. Stair, Peak, or Neither?
签到题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=110;
ll L,R,cnt=0;
void solve()
{
int a,b,c;
cin>>a>>b>>c;
if(a<b&&b<c)
{
cout<<"STAIR"<<endl;
return;
}
else if(b>a&&b>c)
{
cout<<"PEAK"<<endl;
return;
}
else cout<<"NONE"<<endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while(T--) solve();
}
B. Upscaling
用了一个非常蠢的办法,有时间补一下别的做法
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=110;
ll L,R,cnt=0;
string f[40] = {
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##",
"..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##"
};
void solve()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
n*=2;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<f[i][j];
}
cout<<endl;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
}
观察图形,发现规律:4是一个周期,i 和 j 除余4都为0或1时,i和j除余4都为2或3时,输出“#”
优化code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=23;
char f[N][N];
void solve()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
n*=2;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if((i%4<=1&&j%4<=1)||(i%4>1&&j%4>1)) cout<<"#";
else cout<<".";
}
cout<<endl;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
}
C. Clock Conversion
签到题
C语言的printf能自动补前导零的输出方式
(打完才想起来)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=110;
string convertTime(string s) {
int h = stoi(s.substr(0, 2));
int m = stoi(s.substr(3, 2));
string period = (h < 12) ? "AM" : "PM";
if (h == 0) {
h = 12;
} else if (h > 12) {
h -= 12;
}
if (h < 10) {
stringstream ss;
ss << "0" << h << ":" << (m < 10 ? "0" : "") << m << " " << period;
return ss.str();
} else {
stringstream ss;
ss << h << ":" << (m < 10 ? "0" : "") << m << " " << period;
return ss.str();
}
}
void solve() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
cout << convertTime(s) << endl;
}
return;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
}
D. Product of Binary Decimals
罗列出1e5内所有的二进制数
然后再暴搜一遍,把所有二进制数的乘积都枚举一遍
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long,long> pii;
#define int ll
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=1e5+10;
int n;
int res=0;
vector<int>v;
set<int>s;
void dfs(int x,int t)
{
if(t>5)
{
v.push_back(x);
return;
}else
{
v.push_back(x);
x*=10;
dfs(x+1,t+1);
dfs(x,t+1);
}
}
void init(int now)
{
if(now>100000) return;
for(auto x:v)
{
if(!s.count(x*now))
{
s.insert(x*now);
init(x*now);
}
}
return;
}
void solve()
{
int n;
cin>>n;
if(s.count(n)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
dfs(1,0);
init(1);
int T = 1;
cin >> T;
while(T--) solve();
}
E. Nearly Shortest Repeating Substring
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long,long> pii;
#define int ll
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=1e5+10;
ll n;
string s,t;
bool check(int x)
{
int cnts=0,cntt=0;
for(int i=x;i<n;i++)
{
if(s[i%x]!=s[i]) cnts++;
if(t[i%x]!=t[i]) cntt++;
}
if(cnts<=1||cntt<=1) return true;
return false;
}
void solve()
{
cin>>n;
cin>>s;
t=s;
reverse(t.begin(),t.end());
vector<int>v;
for(int i=1;i<=n/i;i++)
{
if(n%i!=0) continue;
v.push_back(n/i);
v.push_back(i);
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
if(check(v[i]))
{
cout<<v[i]<<endl;
return;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while(T--) solve();
}