NEUQ ACM week13周报

特殊的正方形

可以注意到要求输出的图案是对称的

#include<bits/stdc++.h>
using namespace std;
const int N = 110;
char f[N][N];
int n;
int main()
{	
	cin >> n;
	int m = n, l = 0, r = n - 1;
	char s[] = { '+','.' };
	while (m>=0)
	{
		char c = s[l % 2];
		for (int i = 0; i < m; i++)
		{
			f[l + i][r] = c;
			f[l + i][l] = c;
			f[l][l+i] = c;
			f[r][l+i] = c;
		}
		l++, r--;
		m -= 2;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			cout << f[i][j] ;
		cout << endl;
	}
	return 0;
}

走楼梯2

简单dp,值得注意的是,数组要开long long,不然只有80分…

#include <bits/stdc++.h>
using namespace std;
long long f[100][100];
int main()
{
    int n;
    cin>>n;
    if (n<=2)
    {
    	cout<<n;
    	return 0;
    }
    f[0][0]=1;
    for(int i=0;i<=n;i++)
    {
        f[i+1][0]+=f[i][0]+f[i][1]+f[i][2];
        f[i+2][1]+=f[i][0];
        f[i+2][2]+=f[i][1];
    }
    cout<<f[n][0]+f[n][1]+f[n][2]<<endl;
    return 0;   
}

走路

从终点往前推,这样就可以很方便的找出能走到终点的地方

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m;
bool st[110][N];
int main()
{
    cin >> n >> m;
    st[0][0] = true;
    for ( int i = 1; i <= n; i ++ )
    {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        for ( int j = m; j >= a; j -- )
        {
            st[i][j] |= st[i - 1][j - a];
            if (j >= b) st[i][j] |= st[i - 1][j - b];
        }
    }

    for ( int i = 0; i <= m; i ++ )
    {
        if (st[n][i]) cout << "1";
        else cout << "0";
    }

    return 0;
}

简单分数统计

用map记录对应的人名和分数

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 107;
string a[N];
set<string>st;
map<string,int>mp, ans;
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        st.insert(a[i]);
    }
    for (int i = 1; i <= m; i++) {
        string s;
        int t;
        cin >> s >> t;
        mp[s] = t;
    }
    for (int i = 1; i <= k; i++) {
        string name, ques, t;
        cin >> name >> ques >> t;
        if (st.count(name)) {
            if (t == "AC") {
                ans[name] += mp[ques];
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << a[i] << " " << ans[a[i]] << "\n";
    }
    return 0;
}

Alice的德州扑克

枚举

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
int main()
{
	bool two = false, three = false, four = false, flush = true, straight = true, A = false;
	int ans;
	map<int, int>mymap;
	for (int i = 0; i < 5; i++)
	{
		int num;
		cin >> num;
		if (i == 0)ans = num;
		else if (ans + 1 != num)
		{
			straight = false;
		}
		else ans = num;
		mymap[num]++;
		if (i == 4 && num == 14)A = true;
	}
	for (auto i : mymap)
		if (i.second == 2)two = true;
		else if (i.second == 3)three = true;
		else if (i.second == 4)four = true;
	for (int i = 0; i < 5; i++)
	{
		int flu;
		cin >> flu;
		if (i == 0)ans = flu;
		else if (ans != flu)flush = false;
	}

	if (flush && straight && A)cout << "ROYAL FLUSH" << endl;
	else if (flush && straight)cout << "STRAIGHT FLUSH" << endl;
	else if (four)cout << "FOUR OF A KIND" << endl;
	else if (two && three)cout << "FULL HOUSE" << endl;
	else if (flush)cout << "FLUSH" << endl;
	else if (straight)cout << "STRAIGHT" << endl;
	else cout << "FOLD" << endl;

	return 0;
}


订单编号

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<unordered_map>
#include<stack>

typedef long long ll;
typedef pair<int, int>PII;

set<PII>s;

void myinsert(int l, int r)
{
	if (l > r)return;
	s.insert({ r,l });
}

int main()
{
	int n;
	cin >> n;
	s.insert({ 2e9,1 });
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d",&x);
		auto it = s.lower_bound({ x,0 });
		if (it->second <= x)
		{
			cout << x << " ";
			myinsert(it->second, x - 1);
			myinsert(x + 1, it->first);
			s.erase(it);
		}
		else
		{
			cout << it->second << " ";
			myinsert(it->second + 1, it->first);
			s.erase(it);
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值