Codeforces Round 937 (Div. 4) A-E

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能自动补前导零的输出方式

(打完才想起来)

9bd261934ed9417eaf2fbd5fee24892b.png

576277b26be247ec8a12995dba30d717.png

#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

604d7654933a4b29950f85d4494006c5.png

#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();
}

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值