Educational Codeforces Round 41 B、C、D
http://codeforces.com/contest/961
B题 可以将长度为k的连续区间转化成1 求最大和
解析 简单尺取
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <utility>
using namespace std;
const int maxn = 2e5+,maxm = 1e4+;
const int inf = 0x3f3f3f3f,mod = ;
const double epx = 1e-;
typedef long long ll;
const ll INF = 1e18;
const double pi = acos(-1.0);
int n,m,k;
int a[maxn],b[maxn];
int main()
{
cin>>n>>k;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
int sum=;
for(int i=;i<=n;i++)
{
cin>>b[i];
if(b[i])
sum+=a[i];
}
int maxx=-;
int l=,r=,temp=;
while(l<=n-k+)
{
if(r-l<k)
{
if(b[r]==)
temp+=a[r];
r++;
}
else
{
//cout<<l<<" "<<r<<" "<<temp<<endl;
maxx=max(maxx,temp+sum);
if(b[l]==)
sum-=a[l];
l++;
}
}
cout<<maxx<<endl;
}
C题 棋盘分成了大小相同的四块 替换最少的方块 组成一个合格(0,1不相邻)的棋盘
j解析 对于一个合格的棋盘只有两种情况 左上角1 左上角0 四块拼成大棋盘的组合情况有24种 数组范围不大直接每种都跑一边就好了
其实直接枚举6种就好了哪两块左上角为1 C(4,2)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <utility>
using namespace std;
const int maxn = 1e2+,maxm = 1e4+;
const int inf = 0x3f3f3f3f,mod = ;
const double epx = 1e-;
const double pi = acos(-1.0);
typedef long long ll;
const ll INF = 1e18;
int n,m,k,sum;
char a[][maxn][maxn];
char g[*maxn][*maxn];
int vis[*maxn][*maxn];
int dir[][]={{,},{-,},{,},{,-}};
int aa[],xu[][],cnt=;
void dfs(int cur,int n)
{
for(int i=;i<n;i++)
aa[i]=i+cur;
do{
for(int i=;i<n;i++)
xu[cnt][i]=aa[i];
cnt++;
}while(next_permutation(aa,aa+));
}
void DFS(int x,int y,char z)
{
vis[x][y]=;
if((x+y)%==&&g[x][y]!=z)
sum++;
else if((x+y)%==&&g[x][y]==z)
sum++;
for(int i=;i<;i++)
{
int x1=x+dir[i][];
int y1=y+dir[i][];
if(vis[x1][y1]==&&x1>=&&x1<=*n-&&y1>=&&y1<=*n-)
{
DFS(x1,y1,z);
}
}
}
int main()
{
cin>>n;
dfs(,);
int minn=inf;
for(int i=;i<=;i++)
{
for(int j=;j<n;j++)
{
cin>>a[i][j];
}
}
for(int i=;i<cnt;i++)
{
for(int j=;j<;j++)
{
if(j==)
{
for(int k=;k<n;k++)
{
for(int l=;l<n;l++)
{
g[k][l]=a[xu[i][j]][k][l];
}
}
}
else if(j==)
{
for(int k=;k<n;k++)
{
for(int l=;l<n;l++)
{
g[k][l+n]=a[xu[i][j]][k][l];
}
}
}
else if(j==)
{
for(int k=;k<n;k++)
{
for(int l=;l<n;l++)
{
g[k+n][l]=a[xu[i][j]][k][l];
}
}
}
else if(j==)
{
for(int k=;k<n;k++)
{
for(int l=;l<n;l++)
{
g[k+n][l+n]=a[xu[i][j]][k][l];
}
}
}
}
memset(vis,,sizeof(vis));
sum=;DFS(,,'');
minn=min(minn,sum);
memset(vis,,sizeof(vis));
sum=;DFS(,,'');
minn=min(minn,sum);
}
cout<<minn<<endl;
}
D题 n个点 问是否都在 某一条或某两条直线上
解析 n<3 yes n>=3 对于任意三个点a,b,c 若a,b在一条直线上L,除去在L的点,如果剩下的的点在一条直线上 有解
若a,c在一条直线上L,除去在L的点,如果剩下的的点在一条直线上 有解
若b,c在一条直线上L,除去在L的点,如果剩下的的点在一条直线上 有解
若三种情况都没有解 则无解
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <utility>
using namespace std;
const int maxn = 1e6+,inf = 0x3f3f3f3f,mod = ;
const double epx = 1e-;
const double pi = acos(-1.0);
typedef long long ll;
const ll INF = 1e18;
int n,m,k;
typedef pair<int,int> pii;
pii p[maxn];
int vis[maxn];
pii operator -(const pii &a,const pii &b)
{
return {a.first-b.first,a.second-b.second};
}
ll cross(const pii &a,const pii &b)
{
return a.first*1ll*b.second-a.second*1ll*b.first;
}
bool check()
{
int i1=-,i2=-;
for(int i=;i<n;i++)
{
if(vis[i])
continue;
if(i1==-)
i1=i;
else if(i2==-)
i2=i;
}
if(i2==-)
return true;
for(int i=;i<n;i++)
{
if(vis[i])
continue;
if(cross(p[i2]-p[i1],p[i]-p[i1])!=)
return false;
}
return true;
}
bool check2(pii a,pii b)
{
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
{
if(cross(b-a,p[i]-a)==)
vis[i]=;
}
return check();
}
int main()
{
cin>>n;
for(int i=;i<n;i++)
cin>>p[i].first>>p[i].second;
if(n<=)
cout<<"YES"<<endl;
else
{
if(check2(p[],p[])||check2(p[],p[])||check2(p[],p[]))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}
Educational Codeforces Round 41 B、C、D的更多相关文章
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- Educational Codeforces Round 41
Educational Codeforces Round 41 D. Pair Of Lines 考虑先把凸包找出来,如果凸包上的点数大于\(4\)显然不存在解,小于等于\(2\)必然存在解 否则枚 ...
- Educational Codeforces Round 12 B C题、
B. Shopping 题意:n个顾客,每个顾客要买m个物品,商场总共有k个物品,看hint就只知道pos(x)怎么算了,对于每一个Aij在k个物品中找到Aij的位置.然后加上这个位置对于的数值,然后 ...
- Educational Codeforces Round 10 A B题、
A. Gabriel and Caterpillar 题意: 就是说 一个小孩子去观察毛毛虫从 h1的地方爬到h2的地方.毛毛虫从10点爬到22点.每小时爬的距离是a, 晚上22点到第二天早上10点 ...
- Educational Codeforces Round 41 A B C D E
A. Tetris 题意 俄罗斯方块,问能得多少分. 思路 即求最小值 Code #include <bits/stdc++.h> #define F(i, a, b) for (int ...
- 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)
这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...
- Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF
最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...
随机推荐
- git ---回到过去
git命令回顾 git checkout /git reset -git reset HEAD~ //~代表回滚到第几个版本.. 有多个的话可以在~后面加个数字 git reset --mixe ...
- PHP serialize() 序列化函数
PHP serialize() 序列化函数 定义和用法 — 语法 string serialize ( mixed $value ) serialize() 返回字符串,此字符串包含了表示 value ...
- Asp.Net 设计模式 之 “特殊”的单例模式
特殊的单例模式 要点在这里,提前预览: public SingleDemo() { name = "yy"; age = 20; //特殊的单例,this指代得失当前的Single ...
- scss常规用法
保持sass条理性和可读性的最基本的三个方法:嵌套.导入和注释. 一般情况下,你反复声明一个变量,只有最后一处声明有效且它会覆盖前边的值. $link-color: blue; $link-color ...
- centos7.2密码在单用户下面的修改
centos7.2在但用户模式下面的修改 1.开机启动 2.grub模式按E健 3.Linux16行的"ro"修改为 "rw init=/sysroot/bin/sh&q ...
- Swift 性能相关
起初的疑问源自于「在 Swift 中的, Struct:Protocol 比 抽象类 好在哪里?」.但是找来找去都是 Swift 性能相关的东西.整理了点笔记,供大家可以参考一下. 一些疑问 在正题开 ...
- Linux下 SpringBoot jar项目后台运行、查看、停用
运行java jar: nohup java -jar **-0.0.1-SNAPSHOT.jar & 查看进程: 采用top或者ps aux命令.一般 如果后台是springboot,jar ...
- GET方法与POST方法的区别
区别一:get重点在从服务器上获取资源,post重点在向服务器发送数据: 区别二:get传输数据是通过URL请求,以field(字段)= value的形式,置于URL后,并用"?" ...
- 为什么java String是固定的 为什么字符串是不可变的
String类不可变的好处 String是所有语言中最常用的一个类.我们知道在Java中,String是不可变的.final的.Java在运行时也保存了一个字符串池(String pool),这使得S ...
- c++ 回调的实现
什么是回调?通常发生在需要两个角色即调用者与实现者的情形上,即我们希望当产生某个事件时,调用实现者定义的某个函数.当然这个概念很大,不是说操作系统的信号量,条件变量什么的,是在语言级别实现,如一个Fr ...