A.统计每个字母数量,比较是否超过k。

#include<bits/stdc++.h>
using namespace std; int n,k,cnt[] = {};
string s; int main()
{
ios::sync_with_stdio();
cin >> n >> k >> s;
for(int i = ;i < s.length();i++) cnt[s[i]-'a']++;
for(int i = ;i < ;i++)
{
if(cnt[i] > k)
{
cout << "NO" << endl;
return ;
}
}
cout << "YES" << endl;
return ;
}

B.只要有奇数,First必赢,因为总能到奇数个数为奇数个的情况。

#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
int cnt = ;
for(int i = ;i <= n;i++)
{
cin >> a[i];
if(a[i]%) cnt++;
}
if(cnt > ) cout << "First" << endl;
else cout << "Second" << endl;
return ;
}

C.当在[1,x]中随机取一个的时候,最小值期望为x/2,取的次数越多,期望越小。我们把优先次数少的分给大的数。

#include<bits/stdc++.h>
using namespace std; int n,a[],ans[];
struct xx
{
int x,id;
friend bool operator <(xx a,xx b)
{
return a.x > b.x;
}
}b[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
for(int i = ;i <= n;i++)
{
cin >> b[i].x;
b[i].id = i;
}
sort(a+,a++n);
sort(b+,b++n);
for(int i = ;i <= n;i++) ans[b[i].id] = a[i];
for(int i = ;i <= n;i++) cout << ans[i] << " ";
cout << endl;
return ;
}

D.首先图是连通的,若有-1的点存在,则必可以通过这个点,dfs把其它点都调整好。

若没有-1的点存在,我们随便选一个点,dfs下去,最后判断这个点是否符合。

#include<bits/stdc++.h>
using namespace std; int n,m,a[],vis[] = {},dep[] = {};
struct xxx
{
int to,id;
xxx(int a,int b):to(a),id(b){};
};
vector<xxx> v[];
vector<int> ans; bool dfs(int now,int pre)
{
vis[now] = ;
for(int i = ;i < v[now].size();i++)
{
int t = v[now][i].to;
if(t == pre || vis[t]) continue;
if(dfs(t,now))
{
dep[now]++;
ans.push_back(v[now][i].id);
}
}
if(a[now] == && dep[now]% == || a[now] == && dep[now]% == ) return ;
return ;
} int main()
{
ios::sync_with_stdio();
cin >> n >> m;
for(int i = ;i <= n;i++) cin >> a[i];
for(int i = ;i <= m;i++)
{
int x,y;
cin >> x >> y;
v[x].push_back(xxx(y,i));
v[y].push_back(xxx(x,i));
}
int ok = ;
for(int i = ;i <= n;i++)
{
if(a[i] == -)
{
dfs(i,);
ok = ;
break;
}
}
if(!ok && dfs(,))
{
cout << - << endl;
return ;
}
cout << ans.size() << endl;
for(int i = ;i < ans.size();i++) cout << ans[i] << " ";
cout << endl;
return ;
}

Codeforces_841的更多相关文章

随机推荐

  1. 查看磁盘型号和内存及raid信息

    1.查看磁盘型号 工具:smartmontools #smartctl --help #smartctl --all /dev/sda -d megarid,1 (第一块磁盘的信息) #smartct ...

  2. 傅立叶变换—FFT(cuda实现)

    背景: 无意间看到cuda解决FFT有一个cufft函数库,大体查看了有关cufft有关知识,写了一个解决一维情况的cuda代码,据调查知道cufft在解决1D,2D,3D的情况时间复杂度都为O(nl ...

  3. JWT实现授权认证

    目录 一. JWT是什么 二. JWT标准规范 三. 核心代码简析 四. 登录授权示例 五. JWT 使用方式 六. JWT注意事项 一. JWT是什么 JSON Web Token(JWT)是目前最 ...

  4. .net core3.1项目在centos7.6上部署经验

    0x00环境搭建 1)使用PuTTY远程登录你的centos 2)yum -y update 更新系统 3)安装宝塔面板: yum install -y wget && wget -O ...

  5. 关于Integer 和Double包装类创建对象时的底层解析

    public void method1() { Integer i = new Integer(1); Integer j = new Integer(1); System.out.println(i ...

  6. java小项目之:象棋,羡慕你们有对象的!

    象棋,是我国传统棋类益智游戏,在中国有着悠久的历史,属于二人对抗性游戏的一种,由于用具简单,趣味性强,成为流行极为广泛的棋艺活动.中国象棋是中国棋文化也是中华民族的文化瑰宝. 象棋还有很多口诀,这是最 ...

  7. C语言之运算符和表达式

    运算符优先级: 求余运算用法: 声明变量的名字和类型: 变量的类型决定占用内存空间的大小.数据的存储形式,合法的表数范围.可参与的运算种类.变量名标识了内存中的一个存储单元. 自动类型转换: 运算符和 ...

  8. 华为,小米部分机型微信浏览器rem不适配的解决方案

    针对近日华为,小米的部分机型,在升级系统或升级微信之后,微信内置浏览器产生的rem不能正确填充满的问题,有如下解决方案 目前来看,产生这个情况的原因是因为给html附font-size时,附上的fon ...

  9. Miller-Rabin​素数测试算法

    \(Miller-Rabin\)​素数测试 用途 判断整数\(n\)是否是质数,在\(n\)较小的情况下,可以使用试除法,时间复杂度为\(O(\sqrt n)\).但当\(n\)的值较大的时候,朴素的 ...

  10. 基于selenium爬取京东

    爬取iphone 注意:browser对象会发生变化,当对当前网页做任意操作时 import time from selenium import webdriver from selenium.web ...