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连试试水的深浅..... ...
随机推荐
- HTML学习(11)表格
HTML表格由<table>标签定义,下面是一个2行3列的表格: <table> <tr> <td>11</td> <td>12 ...
- 【做题笔记】CF1311A、B、C
或许以后会有D. A 题目大意:给定两个整数 \(a,b\) ,每次可以进行一下任意一个操作: \(a\) 加上任意一个正奇数 \(b\) 减去任意一个正偶数 问是否可以通过若干次操作把 \(a\) ...
- dbShape
Usage: dbShape [-help] [-d] [-step <step>] [-output {polygon rect hrect area}] <shapeList&g ...
- Ubuntu 安装 k8s 三驾马车 kubelet kubeadm kubectl
Ubuntu 版本是 18.04 ,用的是阿里云服务器,记录一下自己实际安装过程的操作步骤. 安装 docker 安装所需的软件 apt-get update apt-get install -y a ...
- Windows10_64位下upload-labs靶场搭建+phpstudy_v8.1安装教程
之前介绍了Windows10_64位搭建WampServer的教程,这一次再来水一篇phpstudy的搭建教程.哈哈哈. 顺便安装一下upload-labs,搭着玩玩~ 操作 ...
- go使用错误概览
1. 解决:GO语言中要提供给外面访问的方法或是结构体必须是首字母大写.这个结构体只有结构体名大写了,而里面的字段没有首字母大写,而GO语言在模板调用时应该认为是两个不同的过程,所以找不到值.于是把结 ...
- 利用mnist训练集生成的caffemodel对mnist测试集与自己手写的数字进行测试
从一到二:利用mnist训练集生成的caffemodel对mnist测试集与自己手写的数字进行测试 通过从零到一的教程,我们已经得到了通过mnist训练集生成的caffemodel,主要包含下面四个文 ...
- JSP技术(二)
参考网址:https://blog.csdn.net/king_cannon_fodder/article/details/79835463 (1)JSP隐式对象(9个内置对象) Servlet容器会 ...
- PHP通过thrift2访问HBASE
前一段时间需要在网页上显示HBASE查询的结果,考虑用PHP来实现,在网上搜了一下,普遍都是用thrift作为接口来实现的. 参考博文: http://www.cnblogs.com/scotom ...
- 程序员过年必备 -- Auto.js微信自动抢红包
打开微信就不用管了: - 自动打开未读消息 - 自动滑动屏幕检测红包 - 自动跳过无效红包 基于Auto JS,apk版本4.01: - 大多数动作均基于控件 - 极个别点击基于动态抓取的坐标 - 这 ...