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.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- .net平台下socket异步通讯(代码实例)
你应该知道的.net平台下socket异步通讯(代码实例) 1,首先添加两个windows窗体项目,一个作为服务端server,一个作为客户端Client 2,然后添加服务端代码,添加命名空间,界面上 ...
- 利用MARQUEE实现正在处理效果
ASP.NET服务器端事件利用MARQUEE实现正在处理效果 前言:ASP.NET同仁们应该都遇到过当触发一个比较耗时的服务器端事件时,页面会处在一个等待的状态(即假死状态),用户体验非常不好,很 ...
- duilib开源界面库
官网: https://code.google.com/p/duilib/ 基于:http://www.viksoe.dk/code/windowless1.htm 教程: http://www.cn ...
- windows下使用git时生成sshkey和配置
在windows下如何安装git就不介绍了,我这里主要使用的TortoiseGit,主要记录下在windows上如何通过sshkey链接git 在开始菜单中找到git bash,git bash是gi ...
- spring.NET的依赖注入
谈谈自己了解的spring.NET的依赖注入 spring.net里实现了控制反转IOC(Inversion of control),也即依赖注入DI(Dependency Injection), ...
- cocos2d(CCSprite 用贝塞尔做抛物线,足球精灵并且同时做旋转放大效果)
今天刚学到Cocos2d中的动作哪一张,自己做了一个用贝塞尔曲线足球精灵实现同时放大旋转和抛物线动作. 使用 [CCSpawn actions:,,]链接这几个动作,同时做.与CCSequence(一 ...
- SharePoint RBS 安装(集成Office Web Apps)
前言 本文完全原创,转载请说明出处,希望对大家有用. 本篇博客是个人总结,一方面以便日后查看,另一方面希望能为其他人提供一些便利. 阅读目录 安装RBS 为多个内容数据库开启RBS 正文 目的:在Sh ...
- 用C#中实现的,调用CMD来执行BCP的代码
用C#中实现的,调用CMD来执行BCP的代码 用c#中实现,调用cmd来执行bcp的代码,大家共享!引用空间:using System;using System.Data;using System.D ...
- 在MVC3中使用WebForm
Mvc和WebForm一直是有争议的两个平台,园子里也有很多人写过这方面的文章,给我印象比较深的是去年的时候看过的两篇文章http://www.cnblogs.com/mikelij/archive/ ...
- .Net用户使用期限的设置、限制通用小组件
.Net用户使用期限的设置.限制通用小组件 最近比较项目组的同事都比较烦,不断的穿梭在不同的项目之间,一个人同时要兼顾多个项目的维护修改.甚至刚放下这个客户的电话,另一个客户的电话就进来了.究其原因, ...