期末后恢复性训练,结果完美爆炸。。。

A,题意:2n个人,分成两队,要求无论怎么分配,第一队打赢第二队

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int a[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<*n;i++)scanf("%d",&a[i]);
sort(a,a+*n);
if(a[n-]==a[n])puts("NO");
else puts("YES");
return ;
}
/******************** ********************/

B题意:有一个6位数,要求改最少的数使得前3个加起来等于后三个加起来

题解:瞎搞都行,我是直接从0for到1000000找最小

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int a[N];
int main()
{
int n;
scanf("%d",&n);
int minn=;
for(int i=;i<;i++)
{
int be=i/;
int en=i%;
int sum1=,sum2=;
while(be)
{
sum1+=be%;
be/=;
}
while(en)
{
sum2+=en%;
en/=;
}
if(sum1==sum2)
{
int di=,te1=i,te2=n;
for(int j=;j<;j++)
{
if(te1%!=te2%)di++;
te1/=;te2/=;
}
minn=min(minn,di);
}
}
printf("%d\n",minn);
return ;
}
/******************** ********************/

C:题意:你有两台电视机,n个节目,从l到r,可以用不同的电视机看两个节目,但是一个节目结束的同时一个节目开始,不能用同一台电视机看

题解:直接模拟,(刚开始还hash了一下,发现根本没必要,简直是sb)

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; struct point{
int l,r;
bool operator <(const point &rhm)const{
if(l!=rhm.l)return l<rhm.l;
return r<rhm.r;
}
}p[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&p[i].l,&p[i].r);
sort(p,p+n);
int t1=-,t2=-;
for(int i=;i<n;i++)
{
if(t1<p[i].l)
{
t1=p[i].r;
}
else
{
if(t2<p[i].l)t2=p[i].r;
else
{
puts("NO");
return ;
}
}
}
puts("YES");
return ;
}
/******************** ********************/

D:题意:你在考驾照,有“限速x,不限速,可以超车,不可以超车”四种牌子,你有6种操作,前面四个和超车和改变速度,问最小的忽略牌子能满足交规的个数

题解:直接模拟,超车和超速可以分开考虑,超速用栈保存,超车直接加即可

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define y1 y2
using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; struct event{
int id,sp;
}e[N];
int over[N];
int main()
{
int n;
scanf("%d",&n);
int cnt1=,cnt2=;
for(int i=;i<n;i++)
{
int a,b=;
scanf("%d",&a);
if(a==||a==)scanf("%d",&b);
if(a==||a==||a==)e[cnt1++]={a,b};
else over[cnt2++]=a;
}
int ans=,i=cnt2-;
while(i>=)
{
if(over[i]==)
{
i--;
while(i>=&&over[i]==)i--,ans++;
}
else i--;
}
int speed=;
stack<int>s;
for(int i=;i<cnt1;i++)
{
if(e[i].id==)
{
speed=e[i].sp;
while(!s.empty()&&speed>s.top())
{
s.pop();
ans++;
}
}
else if(e[i].id==)
{
s.push(e[i].sp);
while(!s.empty()&&speed>s.top())
{
s.pop();
ans++;
}
}
else
{
while(!s.empty())s.pop();
}
}
printf("%d\n",ans);
return ;
}
/******************** ********************/

E:题意:有n*m的块,k个点着火了,每分钟一个点扩散到其他八个点,问找一个点,使得的最小扩散全部的时间

题解:二分答案,判断可行时,先离散化,要注意加上x+q+1的情况,因为中间可能会有两个连起来的情况,然后扫描线跑一边,找没有覆盖的最大矩形,看能不能满足条件

(由于没有考虑x+q+1的情况,导致花了一个下午找bug = = )

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)
using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; struct point{
int x,y;
}p[N];
int n,m,k;
int dp[maxn][maxn];
bool ok(int q)
{
vector<int>vx,vy;
vx.pb(),vx.pb(n);
vy.pb(),vy.pb(m);
for(int i=;i<k;i++)
{
int x1=max(,p[i].x-q);
int x2=min(n,p[i].x+q);
vx.pb(x1);
if(x1->)vx.pb(x1-);
if(x2+<n)vx.pb(x2+); int y1=max(,p[i].y-q);
int y2=max(m,p[i].y+q);
vy.pb(y1);
if(y1->)vy.pb(y1-);
if(y2+<m)vy.pb(y2+);
}
sort(vx.begin(),vx.end());
vx.resize(unique(vx.begin(),vx.end())-vx.begin());
sort(vy.begin(),vy.end());
vy.resize(unique(vy.begin(),vy.end())-vy.begin());
memset(dp,,sizeof dp);
for(int i=;i<k;i++)
{
int x1=max(,p[i].x-q);
int x2=min(n,p[i].x+q)+;
int y1=max(,p[i].y-q);
int y2=min(m,p[i].y+q)+;
x1=lower_bound(vx.begin(),vx.end(),x1)-vx.begin()+;
x2=lower_bound(vx.begin(),vx.end(),x2)-vx.begin()+;
y1=lower_bound(vy.begin(),vy.end(),y1)-vy.begin()+;
y2=lower_bound(vy.begin(),vy.end(),y2)-vy.begin()+;
dp[x1][y1]++;dp[x2][y2]++;
dp[x1][y2]--,dp[x2][y1]--;
}
int xmax=,xmin=vx.size()+,ymax=,ymin=vy.size()+;
for(int i=;i<=vx.size();i++)
{
for(int j=;j<=vy.size();j++)
{
dp[i][j]+=dp[i-][j]+dp[i][j-]-dp[i-][j-];
if(dp[i][j]==)
{
xmax=max(xmax,i);
xmin=min(xmin,i);
ymax=max(ymax,j);
ymin=min(ymin,j);
}
}
}
if(xmax==)return ;
int d=max(vx[xmax-]-vx[xmin-],vy[ymax-]-vy[ymin-]);
if(d&)++d;
d/=;
return d<=q;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<k;i++)
scanf("%d%d",&p[i].x,&p[i].y);
// printf("%d\n",ok(3));
int l=-,r=max(n,m)+;
while(l<r-)
{
int mid=(l+r)>>;
if(ok(mid))r=mid;
else l=mid;
}
printf("%d\n",r);
return ;
}
/******************** ********************/

E

G:题意:有一个无向带权有环图,每两个点之间距离是该路径上的边的权值的异或和,求1到n的最小距离

题解:这题和bzoj2115很相似,可以用线型基求解,先随便找到一条从1到n的路径,记录异或和,把该路径上的环也记录下来,然后对环的所有权值求线型基,最后贪心的选取线型基来和答案异或取最小值

那么,为什么随便找一条路径就可以呢,现在假设有另一条路径更优,那么更优路径和选取的路径构成了一个环,那么如果我们选了这个环,那么异或和就变成更优的那个路径,因此答案还是最小的

线型基在这题中的主要意义是利用最高位的1位置不相同来,使答案中和线型基最高位相同的为1的地方进行异或,这样答案就一定会减小

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define y1 y2
using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; struct edge{
int to,Next,v;
}e[N*];
int head[N],cnt;
void add(int u,int v,int c)
{
e[cnt].to=v;
e[cnt].v=c;
e[cnt].Next=head[u];
head[u]=cnt++;
}
bool vis[N];
int dis[N];
vector<int>v;
void dfs(int u)
{
vis[u]=;
for(int i=head[u];~i;i=e[i].Next)
{
int x=e[i].to;
if(!vis[x])
{
dis[x]=dis[u]^e[i].v;
dfs(x);
}
else
{
v.pb(dis[x]^dis[u]^e[i].v);
if(v[v.size()-]==)v.pop_back();
}
}
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
memset(head,-,sizeof head);
cnt=;
for(int i=;i<m;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
dfs();
// for(int i=0;i<v.size();i++)cout<<v[i]<<"++++"<<endl;
// cout<<dis[n]<<endl;
vector<int>base;
for(int i=;i<v.size();i++)
{
int te=v[i];
for(int j=;j<base.size();j++)
te=min(te,te^base[j]);
if(te)base.pb(te);
}
sort(base.begin(),base.end());
for(int i=base.size()-;i>=;i--)
{
int k=,te=base[i];
while(te)te/=,k++;
k--;
// cout<<k<<" "<<base[i]<<" "<<((dis[n]>>k)&1)<<endl;
if(((dis[n]>>k)&))dis[n]^=base[i];
}
printf("%d\n",dis[n]);
return ;
}
/******************** ********************/

Educational Codeforces Round 27的更多相关文章

  1. Educational Codeforces Round 27 补题

    题目链接:http://codeforces.com/contest/845 A. Chess Tourney 水题,排序之后判断第n个元素和n+1个元素是不是想等就可以了. #include < ...

  2. Educational Codeforces Round 27 A B C

    A. Chess Tourney   Berland annual chess tournament is coming! Organizers have gathered 2·n chess pla ...

  3. Educational Codeforces Round 27 F. Guards In The Storehouse

    F. Guards In The Storehouse time limit per test 1.5 seconds memory limit per test 512 megabytes inpu ...

  4. Educational Codeforces Round 27 D. Driving Test

    单调栈 题意看了半天... #include <cstdio> #include <cstdlib> #include <cmath> #include <c ...

  5. Educational Codeforces Round 117 (Rated for Div. 2)

    Educational Codeforces Round 117 (Rated for Div. 2) A. Distance https://codeforces.com/contest/1612/ ...

  6. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  7. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  8. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  9. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

随机推荐

  1. Django框架--路由分配系统

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  2. java输出pdf

    package snake; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; ...

  3. Python3+Selenium3自动化测试-(三)

    selenium键盘事件 #coding=utf-8 from selenium import webdriver import time from selenium.webdriver.common ...

  4. 六顶思维帽的思考,敏捷开发?——By Me

    人类的思维可以分为很多种,其中按照思维的深度和广度的侧重,可以分为纵向思维和横向思维两种: 简单的来说,“六顶思维帽”可以简单的理解为下图所示: 如何使用这种思维方式呢?举个例子:先输入一个待讨论的事 ...

  5. Tomcat 自定义默认网站目录

    上面访问的网址为http://192.168.0.108:8080/memtest/meminfo.jsp 需求: 现在我想访问格式为http://192.168.0.108:8080/meminfo ...

  6. dedecms中的内容页中的变量

    {dede:php runphp='yes'} var_dump($refObj->Fields); {/dede:php}

  7. Linux环境安装配置maven

     按照下面命令执行即可 1.下载apache-maven-3.5.3-bin.tar.gz 并上传到服务器上 提取地址:https://pan.baidu.com/s/11nxZp84lmonRBCR ...

  8. 简明python教程六----编写一个python脚本

    备份程序: #!/usr/bin/python #Filename:backup_ver1.py import os import time source = ['/home/liuxj/python ...

  9. Linux基础以及简单命令

    1. UNIX是什么 UNIX是一个计算机操作系统,一个用来协调.管理和控制计算机硬件和软件资源的控制程序.特点:多用户和多任务 2. GNU项目与自由软件 GPL条款是为保证GNU软件可以自由地使用 ...

  10. Team Foundation 中的错误和事件消息

    Visual Studio Team System Team Foundation 中的错误和事件消息 Team Foundation 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...