这种凌晨场真的折寿

就过了四题,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的更多相关文章

  1. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  2. Codeforces Round #611 (Div. 3)

    原题面:https://codeforces.com/contest/1283 A.Minutes Before the New Year 题目大意:给定时间,问距离零点零分还有多久? 分析:注意一下 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. apache+SSL 搭建https

    简单介绍 一般情况下,我们打开网站默认的是使用明文传输方式,但在日常生活中,当我们在登录或者支付交易时,网站就会自动跳转至SSL(Secure Sockets Layes)加密传输模式,SSL的功能就 ...

  2. C# virtual 函数

    C# virtual 是虚拟的含义,在 C# 语言中,默认情况下类中的成员都是非虚拟的,通常将类中的成员定义成虚拟的,表示这些成员将会在继承后重写其中的内容. virtual 关键字能修饰方法.属性. ...

  3. spring jdbcTemplate query 返回值为null

    spring jdbcTemplate query 返回值为null 今天使用以下方法从数据库中查询数据,返回列表 public List<BookBean> getBooks(){ St ...

  4. SpringMVC--使用hibernate validator数据校验

    JSR 303 Spring3开始支持JSR 303 验证框架,JSR303是Java为Bean数据合法性校验所提供的标准框架.JSR 303 支持XML和注解风格的验证,通过在Bean属性上标注类似 ...

  5. Panda的学习之路(3)——pandas 设置特定的值&处理没有数据的部分

    先设定好我们的dataframe: # pandas 设置特定的值 dates=pd.date_range(',periods=6) # print(dates) df=pd.DataFrame(np ...

  6. 511,display:inline-block什么时候不会显示间隙?

    (百科: 在CSS布局中,如果我们想要将一些元素在同一行显示,其中的一种方法就是把要同行显示的元素设置display属性为inline-block,但是你会发现这些同行显示的inline-block元 ...

  7. Git - Windows 下, gitbash 打开资源管理器

    1. 概述 windows 下 gitbash 打开 资源管理器 2. 场景 资源管理唤起 gitbash 步骤 进入目录 鼠标右击 在 弹出菜单 中, 找到 Git Bash Here 结果 打开一 ...

  8. 【C语言】(指针) 将两个数排序

    原理就不讲了,这里用来理解指针的使用方法 代码1: #include <stdio.h> int main() { int a, b;/* 实际变量的声明 */ int* p, * q;/ ...

  9. CSS学习(11)常规流

    盒模型:规定单个盒子的规则 视觉格式化模型(布局规则):页面中多个盒子的排列规则 三种方式: 1.常规流 2.浮动 3.定位 常规流布局 常规流   也可以叫做   文档流.普通文档流.常规文档流 所 ...

  10. git相关项目迁移

    1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub. git clone --bare git://github.com/username/project_old.git --bare 创 ...