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

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. Java基础 - 字符串 String

    字符串就是用字符拼接成的文本值,字符串在存储上类似数组,在java语言中把字符串当做对象进行处理 创建字符串 package com.mingri.chapter_02; public class d ...

  2. springmvc控制器controller单例问题

    springmvc controller默认的是单例singleton的,具体可以查看注解scope可以一目了然. 单例的原因有二: 1.为了性能. 2.不需要多例. 1.这个不用废话了,单例不用每次 ...

  3. 原!!win7-64 安装python的 redis客户端库

    安装python的redis客户端库 本人系统已装python2.7 利用cmd命令行: 1.cmd-->python -->>>进入python命令下 >>> ...

  4. 解决:IDEA unable to import maven project see logs for details问题+java http请求报java.net.SocketException: Permission denied:connect 问题

    背景:用IDEA写了一个java发送http请求的maven项目. 运行时,项目报java.net.SocketException: Permission denied:connect问题: 修改po ...

  5. Lua(1)

    1.the use of functions in table fields is a key ingredient for some advanced uses of Lua, such as mo ...

  6. Spring-Spring IoC容器

    IoC容器 Spring容器是Spring框架的核心.容器将创建对象,把它们连接在一起,配置它们,并管理它们的整个生命周期从创建到销毁.Spring容器使用依赖注入(DI)来管理组成一个应用程序的组件 ...

  7. python中decorator的用法及原理(一)

    0. 概念 什么叫装饰器,其实也可以叫做包装器.即对于一个既有的函数func(args),在调用它之前和之后,我们希望都做一些事情,把这个函数包装起来. Python中的装饰器分为两类:函数装饰器和类 ...

  8. Codeforces Round #303 (Div. 2)

    A.Toy Cars 题意:给出n辆玩具车两两碰撞的结果,找出没有翻车过的玩具车. 思路:简单题.遍历即可. #include<iostream> #include<cstdio&g ...

  9. vue-cli中config目录下的index.js文件详解

    vue-cli脚手架工具config目录下的index.js解析 转载自:http://www.cnblogs.com/ye-hcj/p/7077796.html // see http://vuej ...

  10. CodeForces - 987E Petr and Permutations (思维+逆序对)

    题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归 ...