codeforces Round #611
这种凌晨场真的折寿
就过了四题,8wa结尾心态炸裂,求别被hack,再hack就要爬了
A2 B8 C38(1) E1:58(7)
D题感觉可以写,但是没有时间看了。幸好E最后发现了自己的错误。
A题:看到题的时候感觉好温馨,算时间,感动到了
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
const int maxn=1e5+;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,m;
cin>>n>>m;
int sum=-m+(-n)*;
printf("%d\n",sum);
}
return ;
}
B题:看到题的那一刻,又感动到了
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
const int maxn=1e5+;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,m;
cin>>n>>m;
int zx=n/m,ge=m/;
int sheng=n-zx*m;
if(sheng>=ge){
printf("%d\n",zx*m+ge);
}
else{
printf("%d\n",zx*m+sheng);
}
}
return ;
}
C题:这题是hack最多的 QAQ求求求了别注意到我
题意:给n个数字,0或者1~n之间,把0替换成1~n中没出现过的,同时满足不等于它所在的位置下标
思路:暴力……?感觉自己要被hack的……但算了算复杂度没超
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
const int maxn=2e5+;
int a[maxn],pos[maxn]={},p[maxn];
int main()
{
int n;
queue<int>q;
scanf("%d",&n);
int t=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(!a[i]){
p[t++]=i;
}
else{
pos[a[i]]=;
}
}
for(int i=;i<=n;i++){
if(!pos[i]){q.push(i);}
}
for(int i=;i<t-;i++){
int wei=q.front();q.pop();
if(wei!=p[i]){
a[p[i]]=wei;
}
else{
q.push(wei);
wei=q.front();q.pop();
a[p[i]]=wei;
}
}
int wei=q.front();q.pop();int wei2=q.front();
if(p[t-]!=wei && p[t-]!=wei2){
a[p[t-]]=wei;a[p[t-]]=wei2;
}
else{
a[p[t-]]=wei;a[p[t-]]=wei2;
}
for(int i=;i<=n;i++){
printf(i==n?"%d\n":"%d ",a[i]);
}
return ;
}
E题:这是我wa最多,花时间找错误最多的
题意:给一个n,输入n个数(1~n),代表人所在的房子序号,人可以左右移动一格或者不动,但只能移动一次。问最小,最多的可以住不同的房子
思路:缩小,扩大,扩大考虑房子序号出现次数1次,2次,大于等于3次,优先考了右边,然后是不动,再是左边。缩小,遇到房子序号出现次数为0的跳过,遇到不是0的,考虑111,101,110,100四种情况即可。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
const int maxn=2e5+;
int a[maxn]={},vis[maxn]={},pos[maxn]={},k;
int main()
{
int n;
int sum=,ans=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&k);
pos[k]++;
vis[k]++;
}
for(int i=;i<=n;i++){
if(pos[i]==){
if(!a[i-]){a[i-]=;}
else if(!a[i]){a[i]=;}
else if(!a[i+]){a[i+]=;}
}
else if(pos[i]==){
if(!a[i-]){
a[i-]=;
if(!a[i]){a[i]=;}
else if(!a[i+]){a[i+]=;}
}
else{
a[i]=;
a[i+]=;
}
}
else if(pos[i]>=){
a[i]=;a[i-]=;a[i+]=;
}
}
for(int i=;i<=n+;i++){if(a[i]){sum++;}}
for(int i=;i<=n;i++){
if(vis[i] && vis[i+] && vis[i+]){
ans++;i=i+;
}
else if(vis[i] && vis[i+] && !vis[i+]){
ans++;i=i+;
}
else if(vis[i] && !vis[i+] && vis[i+]){
ans++;i=i+;
}
else if(vis[i] && !vis[i+] && !vis[i+]){
ans++;i=i+;
} }
printf("%d %d\n",ans,sum);
return ;
}
D和F等期末考完再补吧。希望期末全过啊
upd
补题D题:
题意:给n个树的位置,求m个人离树最小的距离之和
思路:往外扩,bfs
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
const int maxn=2e5+;
struct node{
int n,m;
node(){}
node(int nn,int mm):n(nn),m(mm){}
};
map<int,bool>vis;
queue<node>q;
int pos[maxn],t=,n,m,k;
ll bfs(){
ll ans=;
while(m> && !q.empty()){
node tk=q.front();q.pop();
if(!vis[tk.n]){
ans+=(ll)tk.m;pos[t++]=tk.n;m--;vis[tk.n]=;
q.push(node(tk.n+,tk.m+));
q.push(node(tk.n-,tk.m+));
}
}
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%d",&k);
vis[k]=;q.push(node(k+,));q.push(node(k-,));
}
printf("%lld\n",bfs());
for(int i=;i<t;i++){
printf(i==t-?"%d\n":"%d ",pos[i]);
}
return ;
}
前几天一直练搜索题……比赛时候搜索题题目都没看……
F题的题意有点难懂
就是给n个1~n的点,第i个点的价值是2^i(0<i<n+1),每个点链接的线,有一个主点和副点,主点的价值等于主点的价值加上其所有的副点价值(包含副点的副点价值等等)
给n-1个数字a,代表价值从大到小的主点位置,求线段两点的价值从大到小的位置
题解,感觉有点像拓扑排序,入度点,并且要求小的先出,所以用优先队列
还是看了别人的题解写的,呜呜呜,题意根本没读懂
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<queue>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
const int maxn=2e5+;
int vis[maxn],du[maxn],a[maxn];
vector<pair<int,int> > v;
priority_queue<int,vector<int>,greater<int> >q;
int n;
int main()
{
cin>>n;
for(int i=;i<n;i++){
cin>>a[i];
vis[a[i]]=,du[a[i]]++;
}
for(int i=;i<=n;i++){
if(!vis[i]){q.push(i);}
}
for(int i=n-;i;i--){
int t=q.top();q.pop();
du[a[i]]--;
v.push_back(make_pair(t,a[i]));
if(!du[a[i]]){q.push(a[i]);}
}
printf("%d\n",a[]);
for(int i=n-;i>=;i--){
printf("%d %d\n",v[i].first,v[i].second);
}
return ;
}
codeforces Round #611的更多相关文章
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #611 (Div. 3)
原题面:https://codeforces.com/contest/1283 A.Minutes Before the New Year 题目大意:给定时间,问距离零点零分还有多久? 分析:注意一下 ...
- Codeforces Round #611 (Div. 3) E
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past ...
- Codeforces Round #611 (Div. 3) C
There are nn friends who want to give gifts for the New Year to each other. Each friend should give ...
- Codeforces Round #611 (Div. 3) D
There are nn Christmas trees on an infinite number line. The ii -th tree grows at the position xixi ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- eclipse报错:unable to install breakpoint in .......due to missing line number attributes
报错信息如下: 解决方案方案1.把断点都干掉,再启动.应该是代码更新后,断点位置没有代码了或位置改变了. 方案2.在Eclipse - Preferences - Java - Complier 下 ...
- 【转载】C++面试题(1-50)
转自http://www.jobui.com/mianshiti/it/cpp/5017/ 1. 面向对象的程序设计思想是什么? 答:把数据结构和对数据结构进行操作的方法封装形成一个个的对象. ...
- php 填写pdf 表单
最近接到新的任务,要求把pdf的文档,编辑后发邮件 首先pdf表单提交,需要用到这个东西pdftk,GitHub地址:https://github.com/mikehaertl/php-pdftk 首 ...
- Windows下MD5校验
参考博客:https://www.cnblogs.com/liubinghong/p/9299276.html 参考博客:https://www.jianshu.com/p/1e1d56552e03 ...
- java获取配置文件中变量值
在resources 目录下新建config.properties文件 #文件保存路径 filePath=E:\\images\\file 工具类 public class ConfigUtil { ...
- FileOutputStream,BufferedOutputStream,FileWriter 效率比较
测试代码: /** * 写文件 * FileOutputStream, BufferedOutputStream, FileWriter * 三个流 效率比较 */ @Test public void ...
- Python实验案例
Python 运算符.内置函数 实验目的: 1.熟练运用 Python 运算符. 2.熟练运用 Python 内置函数.实验内容: 1.编写程序,输入任意大的自然数,输出各位数字之和. 2.编写程序, ...
- dk7和jdk8的一些新特性
本文是我学习了解了j 的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwork/java/javase/jdk7-relnotes- ...
- vue 一些学习笔记
var, let, const 区别 //-----------------var----------------- var a = []; for(var i= 0; i < 10; i++) ...
- for语句处理多维数组
看C++Primer第三章看到的,记录一下. 下面这段代码非法,因为row指向的是每一行的一个大小为10的一维数组,默认转为指针,即row其实是一个int*类型的指针,显然内层循环就出错了 int a ...