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. WTM 3.1发布,完美支持.netcore 3.1

    在过去的2019年,承蒙各位的厚爱,WTM从零开始一年的时间在GitHub上收获了将近1600星,nuget上的下载量累计超过10万. WTM所坚持的低码开发,快速实现的理念受到了越来越多.netco ...

  2. 微信公众号 唤醒手机导航APP 一看就懂 复制即用

    公司自研发框架,基本上没啥看不懂的 基本都是直接复制用就好了!希望能帮助到需要的朋友! 新建俩个同级文件用来保存 jsapi_ticket 和 access_token的文件 命名:jsapi_tic ...

  3. js提取JSON数据中需要的那部分数据

    var data =[ { name: "程咬金",sex:"1",age:26 }, { name: "程才",sex:"0&q ...

  4. TensorFlow——tensorflow编程基础

    0.tensorflow中的模型运行基础 tensorflow的运行机制属于定义和运行相分离,在操作层面可以抽象成两种:模型构建和模型运行. 在模型构建中的常见概念: 张量(tensor):数据,即某 ...

  5. Scala实践4

    一.数组 在Scala中,用()来访问元素,数组声明的语法格式如下 : var z:Array[String] = new Array[String](3) 或 var z = new Array[S ...

  6. a标签点击触发 layer open 只显示背景解决

    问题:公司网站突然说有个查看信息的点击不好使了,有时候点击无反应,但是href执行了,有时候弹出只有背景,不显示内容.网上找了a标签的各种方法尝试后,均不能解决. 代码:类似如下,method()方法 ...

  7. 【LC_Overview1_5】---学会总结回顾

    刷LeetCode题目一周,主要采用C++和Python编程手段,截至目前做了5道简单的leetcode题目,做下阶段性的小结: 小结主要通过手撕代码,复习加回顾,尽量避免自己眼高手低的情况发生,对于 ...

  8. DbCommand :执行超时已过期。完成操作之前已超时或服务器未响应。

    问题:“Timeout 时间已到.在操作完成之前超时时间已过或服务器未响应.”的解决方法 在一个链接数据库的时候,老是出现超时的错误:执行超时已过期.完成操作之前已超时或服务器未响应. 就是给这个链接 ...

  9. NETCore下IConfiguration和IOptions的用法

    NETCore下IConfiguration和IOptions的用法 https://www.cnblogs.com/RainingNight/p/strongly-typed-options-con ...

  10. CAS是什么

    CAS是什么? 比较并交换 例子1: public class ABADemo1 { public static void main(String[] args) { AtomicInteger at ...