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

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. Design Pattern - 访问者模式

    访问者模式 访问者模式(Visitor), 表示一个作用于某对象结构中的各元素的操作.它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作. 这个模式相对比较复杂, 而又很少能被用上, 拿G ...

  2. Gson 解析多层嵌套JSON数据

    http://stackoverflow.com/questions/14139437/java-type-generic-as-argument-for-gson

  3. rest_framake之视图

    开始,先放大招 一  最原始的写法 前戏之序列化 class AuthorSerializer(serializers.ModelSerializer): class Meta: model = mo ...

  4. mysq查询语句包含中文以及中文乱码,字符集 GBK、GB2312、UTF8的区别

    一.查看mysql 字符集设置情况 使用Navicat for Mysql查看工具,打开命令列界面,输入show variables like '%char%';如下图,查看当前mysql字符集设置情 ...

  5. IOS研究之IOS7四种后台机制

     IOS 7中,实际上APP拥有四种后台模式.不管是哪一种后台机制,均须要利用苹果给予的对应后台接口实现.IOS7系统中,开发人员能够灵活利用多种后台接口(API)实现更加智能的应用操作. 对获取 ...

  6. EJB远程客户端和本地客户端

    在客户端中使用企业bean 企业bean的客户端通过依赖注入或JNDI查询的方式获得对企业bean实例的引用. 依赖注入是获得对企业bean实例的引用的最简便的方法. (紧耦合的bean之间相互依赖, ...

  7. EXP直接导出压缩问津,IMP直接导入压缩文件的方法

    在10G之前,甚至在10G的Oracle环境中,有很多数据量不大,重要性不太高的系统依然采用EXP/IMP逻辑导出备份方式,或者,作为辅助备份方式. 通常情况下,我们都是这样操作的:1.exp导出2. ...

  8. 关于 sql server 基本使用的建议

    1.   把现有的表插入到新表,(表不能存在),为表备份. --  select  *  into  NewTable   from  OldTable   (NewTable 在select 查询的 ...

  9. python 中的 re.compile 函数(转)

    1. 使用re.compile re模块中包含一个重要函数是compile(pattern [, flags]) ,该函数根据包含的正则表达式的字符串创建模式对象.可以实现更有效率的匹配.在直接使用字 ...

  10. arcgis中给属性文件加x y坐标

    两种方式: 一, 1在ArcGIS 9.2桌面软件arcview级别以上软件中,加载要添加x,y坐标的数据,打开属性表,添加X.Y字段 2 右键X字段,选择calculate geometry,如果颜 ...