Educational Codeforces Round 41 (Rated for Div. 2)
这场没打又亏疯了!!!
类似俄罗斯方块,模拟一下就好啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=+;
const int M=; int n, m; int cnt[N];
int main() { int ans = ;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++) {
int x; scanf("%d", &x);
cnt[x]++; bool flag = true;
for(int j = ; j <= n; j++) {
if(cnt[j] == )
flag = false;
} if(flag) {
ans++;
for(int j = ; j <= n; j++) {
cnt[j] -= ;
}
}
} printf("%d\n", ans);
return ;
}
/*
*/
瞎模拟一下就好啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1e5+;
const int M=; int n, k, a[N], t[N],sum1[N], sum2[N]; int main() { scanf("%d%d", &n, &k); for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
sum1[i] = sum1[i-] + a[i];
} for(int i = ; i <= n; i++) {
scanf("%d", &t[i]);
sum2[i] = sum2[i-];
if(t[i])
sum2[i] += a[i];
} int ans = sum2[n]; for(int i = ; i + k - <= n; i++) {
ans = max(ans, sum2[n] + (sum1[i+k-] - sum1[i-]) - (sum2[i+k-] - sum2[i-]));
} printf("%d\n",ans);
return ;
}
/*
*/
每个块只有两种情况,第一种是第一个数字为0,第二种是第一个数字为1,把每个块这两种情况需要修改的个数记录下来,
然后暴力枚举就好啦 。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1e5+;
const int M=; int n, a[][], s[][],id[];
int main() { scanf("%d", &n); for(int k = ; k < ; k++) {
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
scanf("%1d", &s[i][j]);
}
} int flag = ;
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
if(flag != s[i][j])
a[k][]++;
flag ^= ;
}
} flag = ;
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
if(flag !=s[i][j])
a[k][]++;
flag ^= ;
}
}
}
for(int i = ; i < ; i++)
id[i] = i; int ans = inf;
do
{
ans = min(ans, a[id[]][] + a[id[]][] + a[id[]][] + a[id[]][]);
}while(next_permutation(id, id + )); for(int i = ; i < ; i++)
id[i] = i; do
{
ans = min(ans, a[id[]][] + a[id[]][] + a[id[]][] + a[id[]][]);
}while(next_permutation(id, id + )); printf("%d\n", ans);
return ;
}
/*
*/
题意:给你若干个点,问你能不能最多划两条直线覆盖所有点。
思路:先找到三个不共线的点组成一个三角形,其中一条边一定是需要划的直线,枚举一下这三条边,然后check一下剩下的
点在不在一条直线上。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
using namespace std; typedef long long LL;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=1e5+;
const int M=; struct point {
LL x, y;
}p[N]; LL aross(point a, point b, point c) {
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
} vector<point> v;
int n;
int main() { scanf("%d", &n); if(n <= ) {
puts("YES");
return ;
}
for(int i = ; i < n; i++) {
scanf("%lld", &p[i].x);
scanf("%lld", &p[i].y);
} int pos = ; while(pos < n && !aross(p[], p[], p[pos]))
pos++; if(pos == n) {
puts("YES");
return ;
} else { for(int i = ; i < n; i++) {
if(aross(p[], p[], p[i]) != )
v.push_back(p[i]);
} if(v.size() <= ) {
puts("YES");
return ;
} bool flag = true; for(int i = ; i < v.size(); i++) {
if(aross(v[], v[], v[i]) !=) {
flag = false;
break;
}
} if(flag) {
puts("YES");
return ;
} v.clear();
for(int i = ; i < n; i++) {
if(aross(p[], p[pos], p[i]) != )
v.push_back(p[i]);
} if(v.size() <= ) {
puts("YES");
return ;
} flag = true; for(int i = ; i < v.size(); i++) {
if(aross(v[], v[], v[i]) !=) {
flag = false;
break;
}
} if(flag) {
puts("YES");
return ;
} v.clear();
for(int i = ; i < n; i++) {
if(aross(p[], p[pos], p[i]) != )
v.push_back(p[i]);
} if(v.size() <= ) {
puts("YES");
return ;
} flag = true; for(int i = ; i < v.size(); i++) {
if(aross(v[], v[], v[i]) !=) {
flag = false;
break;
}
} if(flag) {
puts("YES");
return ;
} puts("NO");
}
return ;
}
/*
*/
裸的主席树,没啥好说的,数组开小了两次一次WA,一次RE。。。
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
using namespace std; typedef long long LL;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=4e5+;
const int M=; int root[N],hs[N],a[N],tot;
struct Chairman_tree
{
int cnt;
struct node{
int l,r;
ll sum;
}a[*N];
void update(int l,int r,int &x,int y,int pos,int v)
{
a[++cnt]=a[y];
x=cnt; a[x].sum+=v;
if(l==r) return;
int mid=(l+r)>>;
if(pos<=mid)
update(l,mid,a[x].l,a[y].l,pos,v);
else
update(mid+,r,a[x].r,a[y].r,pos,v);
}
ll query(int l,int r,int L,int R,int x)
{
if(l >= L && r <= R)
return a[x].sum;
ll ans = ;
int mid = (l + r) >> ;
if(L <= mid)
ans += query(l,mid,L,R,a[x].l);
if(R > mid)
ans += query(mid + ,r,L,R,a[x].r);
return ans;
}
}seg; int n;
int main() { scanf("%d", &n); for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
hs[++tot] = a[i];
hs[++tot] = i;
} sort(hs + , hs + tot + );
tot = unique(hs + , hs + tot + ) - hs - ; for(int i = ; i <= n; i++) {
int pos = lower_bound(hs+,hs++tot,a[i])-hs;
seg.update(,tot,root[i],root[i-],pos,);
} ll ans = ;
for(int i = ; i <= n; i++) {
int item = lower_bound(hs+,hs++tot,i)-hs;
int pos = min(i - , a[i]);
ans += seg.query(, tot, item, tot, root[pos]);
} printf("%lld\n",ans);
return ;
}
/*
*/
Educational Codeforces Round 41 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings
题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...
- Educational Codeforces Round 41 (Rated for Div. 2)(A~D)
由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...
- Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF
最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...
- D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))
#include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...
- C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))
//暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...
- B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))
前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
- Educational Codeforces Round 41 (Rated for Div. 2) D. Pair Of Lines (几何,随机)
D. Pair Of Lines time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- 【题解】 [SCOI2010]连续攻击游戏 (二分图匹配)
原题目戳我 Solution: 方法很巧妙,我们把每个装备的属性 与 装备编号连起来 从1-10000跑二分图,如果出现断层,就退出,输出答案就好. memset清理bool快一点,int洛谷上超时了 ...
- 浅谈移动端 View 的显示过程
作者:个推安卓开发工程师 一七 随着科技的发展,各种移动端早已成为人们日常生活中不可或缺的部分,人们使用移动端产品工作.社交.娱乐……移动端界面的流畅性已经成为影响用户体验的重要因素之一.那么你是否思 ...
- 使用 Nginx 和 Gunicorn 部署 Django 博客(转)
原文:http://zmrenwu.com/post/20/ http://www.siar.me/post/9/ 针对很多朋友反映按照教程的做法始终只能看到 Nginx 欢迎页面的问题,Tian ...
- centos6 pyenv和virtualenv搭建python虚拟环境
安装pyenv 基础环境软件包安装 yum -y install gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel ...
- python删除列表元素remove,pop,del
python删除列表元素 觉得有用的话,欢迎一起讨论相互学习~Follow Me remove 删除单个元素,删除首个符合条件的元素,按值删除,返回值为空 List_remove = [1, 2, 2 ...
- Java技术体系总结
PC前端:Javascript.JQuery.Angularjs.Reactjs.TypeScript 移动前端:Vue.js.Zepto WebJars spring:spring mvc.spri ...
- 略显犀利的 js 判断闰年
/** * 判断闰年函数 * @param {number} year 要判断的年份 * @return {bool} 返回布尔值 * * 其实只要满足下面几个条件即可. * 1.普通年能被4整除且不 ...
- 浅谈区间DP的解题时常见思路
一.区间DP解题时常见思路 如果题目中答案满足: 大的区间的答案可以由小的区间答案组合或加减得到 大的范围可以由小的范围代表 数据范围较小 我们这时可以考虑采用区间DP来解决. 那么常见的解法有两种: ...
- Caffe 碎碎念
Window Data Layer window data layer 的数据是存在硬盘上的图片, 需要在一个txt里指定用于训练或测试的图片以及bounding box, bounding box ...
- 春夏秋冬又一春之Redis持久化
历史文章推荐: 一只准程序猿的唠叨 可能是最漂亮的Spring事务管理详解 Java多线程学习(八)线程池与Executor 框架 面试中关于Redis的问题看这篇就够了 非常感谢<redis实 ...