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 ...
随机推荐
- c# DataGridView绑定DataTable对象之后总会多一行
DataGridView 属性 AllowUserToAddRows = false
- c# winform 为按钮动态背景图片
参考自:http://www.cnblogs.com/sufei/archive/2012/11/15/2771299.html 第一种,使用Properties.Resources类,这种方法需要你 ...
- HGOI20180812 (NOIP2018 提高组 Day1 模拟试题)
前缀数组其实就是有序的,那么答案显然是 我们尝试求出通项公式: 证明如下: 因为 所以: 解之得: 更加通俗的写法如下: 易知 令 那么, (错位相减) 由易知等式代入得, 所以, 所以程 ...
- 哈夫曼树;二叉树;二叉排序树(BST)
优先队列:priority_queue<Type, Container, Functional>Type 为数据类型, Container 为保存数据的容器,Functional 为元素比 ...
- os.chmod()--更改目录授权权限
用法:os.chmod() 方法用于更改文件或目录的权限. 语法:os.chmod(path, mode) 参数:只需要2个参数,一个是路径,一个是说明路径的模式. path -- 文件名路径或目录路 ...
- 关于Thinkphp5类命名导致的“模块不存在”问题
不得不说,thinkphp5就是个十足的坑货, 在thinkphp3.2.3的基础上,函数.用法变了也就忍了, 在mac下写的一个类文件 GetRedisData.php,在mac+mamp环境下是正 ...
- Linux ------清除内存中的cache
首先以Centos6.4的来说,Centos7有些区别 一.buffer/cache/swap的介绍 #cat /etc/redhat-release #查看系统版本 CentOS release ...
- HTML5 中 Geolocation 获取地理位置的原理是什么?
http://www.zhihu.com/question/20473051?sort=created geolocation的位置信息来源包括GPS.IP地址.RFID.WIFI和蓝牙的MAC地址. ...
- 原生JS不到30行,实现类似javascript MVC的功能-minTemplate
严格来讲不能说是MVC,应为模版里不能写逻辑语句. 灵感来源于我的上篇文字:<封装JSON数据转自定义HTML方法parseHTML>: 这里再封装一个简单方法,在保持原来的方便改变不大的 ...
- Docker学习笔记二 使用镜像
本文地址:https://www.cnblogs.com/veinyin/p/10408363.html Docker运行容器前,需本地存在对应镜像,若没有则Docker从镜像仓库下载该镜像. 镜 ...