这场没打又亏疯了!!!

A - Tetris :

类似俄罗斯方块,模拟一下就好啦。

 #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 ;
}
/*
*/

B - Lecture Sleep

瞎模拟一下就好啦。

 #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 ;
}
/*
*/

C - Chessboard

每个块只有两种情况,第一种是第一个数字为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 ;
}
/*
*/

D - Pair Of Lines

题意:给你若干个点,问你能不能最多划两条直线覆盖所有点。

思路:先找到三个不共线的点组成一个三角形,其中一条边一定是需要划的直线,枚举一下这三条边,然后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 ;
}
/*
*/

E - Tufurama

裸的主席树,没啥好说的,数组开小了两次一次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)的更多相关文章

  1. Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings

    题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...

  2. Educational Codeforces Round 41 (Rated for Div. 2)(A~D)

    由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...

  3. Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF

    最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...

  4. D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))

    #include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...

  5. C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))

    //暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...

  6. B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))

    前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...

  7. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

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

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

随机推荐

  1. 【BZOJ5138】[Usaco2017 Dec]Push a Box(强连通分量)

    [BZOJ5138][Usaco2017 Dec]Push a Box(强连通分量) 题面 BZOJ 洛谷 题解 这题是今天看到萝卜在做然后他一眼秒了,我太菜了不会做,所以就来做做. 首先看完题目,是 ...

  2. 解题:SPOJ 3734 Periodni

    题面 按列高建立笛卡尔树,转成树上问题...... 笛卡尔树是什么? 它一般是针对序列建立的,是下标的BST和权值的堆(即中序遍历是原序列连续区间,节点权值满足堆性质),这里不讲具体怎么建树(放在知识 ...

  3. mysql、mybatis遇到问题集合

    1.错误描述 使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more th ...

  4. UDP ------ UDP 和 TCP 的对比

    UDP是无连接协议,客户端和服务器通信之前不需要建立握手连接: UDP没有应答机制,所以也没有重发机制,很大的可能会造成丢包.收到重复包.乱序的情况: UDP可以实现局域网广播功能,即某个主机可以向所 ...

  5. linux c 编程 ------ 获取时间,计算程序执行时间

    #include <time.h> #include <stdio.h> #include <unistd.h> int main(int argc, char a ...

  6. Random Projection在k-means的应用

    1. 随机投影 (Random Projection) 首先,这是一种降维方法.之前已经介绍过相对普遍的PCA的降维方法,这里介绍另一种降维方法Random Project.相比于PCA,他的优势可以 ...

  7. Dubbo学习笔记10:Dubbo服务消费方启动流程源码分析

    同理我们看下服务消费端启动流程时序图: 在<Dubbo整体架构分析>一文中,我们提到服务消费方需要使用ReferenceConfig API来消费服务,具体是调用代码(1)get()方法来 ...

  8. hdu 4857 Little Devil I

    http://acm.hdu.edu.cn/showproblem.php?pid=4897 题意:给你一棵树,边的颜色要么为白色,要么为黑色,初始每条边为白色,有三种操作 1.将u-v链上面的所有边 ...

  9. c#的as,is 运算符

  10. '增量赋值(augmented assignment)', 多么痛的领悟!

    '增量赋值(augmented assignment)', 多么痛的领悟! 深刻理解x += a 与 x = x + a 的不同: 按理说上面的两条语句是等价的, 功能上完全一样的. 之所以说不同, ...