think-cell Round 1

文章介绍了三道编程题目,涉及贪心策略、排序、不重复元素的处理以及字符串子串的区间覆盖计算,展示了在Codeforces竞赛中解决这些问题的C++代码实现。

A.

贪心,排序完找2个2个之间最大即可

// Problem: A. Maximise The Score
// Contest: Codeforces - think-cell Round 1
// URL: https://codeforces.com/contest/1930/problem/0
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
ll a[N];
void Lan(){
	int n;
	cin>>n;
	for(int i=1;i<=2*n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+2*n);
	ll ans=0;
	for(int i=1;i<=2*n;i+=2){
		ans+=a[i];
	}
	cout<<ans<<'\n';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

B.

构造,大的在前面必然不能把小的平分

大小大小

// Problem: B. Permutation Printing
// Contest: Codeforces - think-cell Round 1
// URL: https://codeforces.com/contest/1930/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		a[i]=i;
	}
	int l=1,r=n;
	while(l<r){
		cout<<a[r]<<" ";
		r--;
		cout<<a[l]<<" ";
		l++;
	}
	if(n&1){
		cout<<a[r];
	}
	cout<<'\n';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

C.

贪心,排序,不重复即可

#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
const int N=3e5+9;
int a[N];
inline void lan(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){//模拟操作
        a[i]+=i;
    }
    sort(a+1,a+1+n,greater<int>());
    for(int i=2;i<=n;i++){//不重复
        a[i]=min(a[i],a[i-1]-1);//a[i],a[i]重复,(a[i]-1)
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<" ";
    }
    cout<<'\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int q;
    cin>>q;
    while(q--){
        lan();
    }
    return 0;
}

D1.

题意是给定一个字符串,求每个子串要几个区间为三的101覆盖,然后求和

#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
const int N=2e5+9;
int a[N];
inline void lan(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=i;k<=j;k++){
                if(s[k]=='1'){
                    ans++;
                    k+=2;
                }
            }
        }
    }
    cout<<ans<<'\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int q;
    cin>>q;
    while(q--){
        lan();
    }
    return 0;
}

<template> <van-form @submit="submitForm" @failed="onFailed" ref="ruleFormRef" :model="form"> <van-cell-group> <van-field v-model="form.username" label="账号:" placeholder="请输入账号" clearable name="username" :rules="usernameRules" ></van-field> </van-cell-group> <van-cell-group> <van-field v-model="form.password" label="密码:" placeholder="请输入密码" name="password" clearable type="password" :rules="passwordRules" ></van-field> </van-cell-group> <van-cell-group> <van-button block round type="primary" native-type="submit">登录</van-button> </van-cell-group> </van-form> </template> <script setup> import { ref, reactive } from 'vue' import { login, getUser } from '../api' import useToken from '../stores/token' import useUser from '../stores/user' import { useRouter } from 'vue-router' const { updateToken } = useToken() const { updateUser } = useUser() const router = useRouter() const form = reactive({ username: 'jhh', password: '123456' }) const ruleFormRef = ref() // 定义验证规则 const usernameRules = ref([ { required: true, message: '用户名不能为空' }, { pattern: /^\w{3,16}$/, message: '用户名长度为3-16个字符' } ]) const passwordRules = ref([ { required: true, message: '密码不能为空' }, { pattern: /^\w{6,24}$/, message: '密码必须为6-24位英文字母或数字' } ]) // 表单提交函数 const submitForm = async values => { const data = await login(values) if (data) { updateToken(data.token) const user = await getUser() updateUser({ isLogin: true, username: user.username, avatar: user.avatar }) router.push({ name: 'user' }) } } const onFailed = errorInfo => { console.log('failed', errorInfo) } </script> <style lang="less" scoped> button { position: fixed; top: 200px; } </style>
07-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值