Codeforces Round #390 (Div. 2)
时隔一个月重返coding……
期末复习了一个月也不亏 倒是都过了……
就是计组61有点亏 复变68也太低了 其他都还好……
假期做的第一场cf 三道题 还可以……
最后room第三 standing383简直人生巅峰……
看楼上楼下都是两道题的 如果A题不错那么多估计能进前300了吧……
这场倒是把之前两场的分加回来了 开头不错 这个假期争取紫名~
A.Lesha and array splitting
把给定的数组分割成几个区间 要求各个区间和不能为0
一开始没注意到分割之后的区间重新合成之后还是这个区间错了好几发……
具体思路见注释
#include <bits/stdc++.h>
using namespace std; int a[]; int main()
{
int n;
int p = -, sum = ;
scanf("%d",&n);
for (int i = ; i <= n; i ++)
{
scanf("%d",&a[i]);
sum += a[i];
if (a[i] != && p == -)
{
p = i;
}
}
if (p == -)
{//都是零的话肯定不行
puts("NO");
}
else
{
puts("YES");
if (sum != )
{//数列和不为零 那么一个区间就够了
printf("1\n1 %d\n",n);
}
else
{//数列和为零的话 取最前面的分割点就好了
printf("2\n1 %d\n%d %d\n", p, p+, n);
}
}
return ;
}
B.Ilya and tic-tac-toe game
题意就是问该下的人再下一步能不能赢
4x4的格子强行暴力
#include <bits/stdc++.h>
using namespace std; char mp[][],one; int main()
{
int nx=,no=;
for(int i=; i<; i++)
{
gets(mp[i]);
for(int j=; j<; j++)
{
if(mp[i][j]=='x') nx++;
if(mp[i][j]=='o') no++;
}
}
if(no==nx) one='x';
else one='o';
bool ok=false;
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(mp[i][j]=='.') //这个地方是空的 假如把棋子下在这
{
mp[i][j]=one;
for(int k=; k<; k++)
{
for(int l=; l<; l++)
{
if(k < && mp[k][l] == one && mp[k+][l] == one && mp[k+][l] == one) ok=true;
if(l < && mp[k][l] == one && mp[k][l+] == one && mp[k][l+] == one) ok=true;
}
}
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(mp[][] == one && mp[][] == one && mp[][] == one) ok = true;
if(ok)
{
printf("YES");
return ;
}
else mp[i][j]='.'; //没赢 换个地方下
}
}
}
printf("NO\n");
return ;
}
C.Vladik and chat
是个大模拟 还没弄明白……
D.Fedor and coupons
数据结构题
给你n个区间 选择k个求最长交集
自己做没做出来 和别人交流了一下才知道是个堆 现学现卖了一发
写了一个堆 维护前k大值 假设区间i作为最后一个区间必选
ans=max(前i-1个区间右端点的k-1大值,第i区间右端点的最小值) - 第i个区间左端点
#include<bits/stdc++.h>
using namespace std; const int maxn=3e5+; struct A
{
int x, y, id;
} a[maxn]; bool cmp(A x,A y)
{
return x.y == y.y ? x.x < y.x : x.y > y.y;
} priority_queue<int> q;
int ans = , r = -,n, k; void solve() //优先队列维护k大值
{
q.push(-2e9);
for (int i = ; i < n; i ++)
{
if (q.size() == k)
{
int l = max(q.top(), a[i].x);
if (a[i].y - l + >= ans)
{
ans = a[i].y - l + ;
r = a[i].y;
}
}
q.push(a[i].x);
if (q.size() > k)
{
q.pop();
}
}
} void print()
{
if(ans)
{
int l = r - ans + ;
for (int i = ; k > ; i ++)
{
if (a[i].x <= l && a[i].y >= r)
{
k --;
printf("%d ",a[i].id);
}
}
}
else
{
for (int i = ; i < k; i ++)
{
printf("%d ",a[i].id);
}
}
} int main()
{
scanf("%d%d",&n,&k);
for (int i = ; i < n; i ++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].id = i + ;
}
sort(a, a + n, cmp); //按区间边界排序
solve();
printf("%d\n",ans);
print();
return ;
}
/* */
E.Dasha and cyclic table
没看懂……
巨巨们讨论的热火朝天 我却啥都听不懂……
等能听懂他们说啥应该就有很大进步了吧……
Codeforces Round #390 (Div. 2)的更多相关文章
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)
http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...
- Codeforces Round #390 (Div. 2) A. Lesha and array splitting
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...
- Codeforces Round #390 (Div. 2) E(bitset优化)
题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...
- Codeforces Round #390 (Div. 2) A B C D
这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...
- Codeforces Round #390 (Div. 2) D
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...
- Codeforces Round #390 (Div. 2) B
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. ...
- Codeforces Round #390 (Div. 2) A
One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into sev ...
- Codeforces Round #390 (Div. 2) A+B+D!
A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- ASP.NET MVC应用程序使用异步及存储过程
ASP.NET MVC应用程序使用异步及存储过程 是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译 ...
- malloc内存分配与free内存释放的原理
malloc内存分配与free内存释放的原理 前段时间一直想看malloc的原理,在搜了好几篇malloc源码后遂放弃,晦涩难懂. 后来室友买了本深入理解计算机系统的书,原来上面有讲malloc的原理 ...
- Asp.net MVC集成Google Calendar API(附Demo源码)
Asp.net MVC集成Google Calendar API(附Demo源码) Google Calendar是非常方便的日程管理应用,很多人都非常熟悉.Google的应用在国内不稳定,但是在国外 ...
- 获取时间SQL函数语句
1.获取时间 获取当天的数据 where DATEDIFF (DD, 数据库中时间的字段 ,GETDATE())=0 查询24小时内的 where DATEDIFF (HH, 数据库中时间的字段 ...
- JS树型菜单
本树型菜单主要实现功能有:基本的树型菜单,可勾选进行多选项操作. 本树型菜单适合最初级的学者学习,涉及内容不难,下面看代码. 首先看View的代码,第一个<div>用来定义树显示的位置和i ...
- jQuery获取checkbox选中项等操作及注意事项
jQuery获取checkbox选中项等操作及注意事项 今天在做一个项目功能时需要显示checkbox选项来让用户进行选择,由于前端不是很熟练,所以做了一个简单的Demo,其中遇到一些小问题,特记录下 ...
- Aliexpress API 授权流程整理
Aliexpress API 授权流程整理 前言 我零零总总用了好几个月的时间,写了一个自用的小程序,从 Aliexpress 上抓取订单的小程序.刚开始写的时候,该API还没有开放,而且没有订单 ...
- 随机生成n个不相等的随机数
在计算机视觉中,(例如8点算法)经常用到RANSAC算法在N个数据中找到最合适的一组n(n<N)个数据对,使某项指标达到最大.解决这个问题需要随机的在N个数据对中采样.本文实现一种线性的,复杂度 ...
- JQUERY UI DOWNLOAD
JQUERY UI DOWNLOAD jDownload是jQuery的一个下载插件,用户可以在下载文件之前知道文件的详细信息,在提高用户体验度方面起到了很大的作用. 鉴于官网的Demo是通过PHP文 ...
- 风萧萧兮易水寒 coding一去兮不复还
这一年都在忙碌中渡过.没有看过日落没有享受过日常.希望可以在忙碌中有些收获.工作马上要三年了. 风萧萧兮易水寒 coding一去兮不复还 记的刚毕业的时候喜欢自己晚上更新下博客.那时候也很忙.但是后来 ...