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

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 常用语法和数据结构

    Collection 首先Java中的collection都是支持泛型和类型安全 由于Java单根继承, 所以不指定, 可以在collection里面放任何对象, collection会都当作obje ...

  2. django模板复用 extends,block,include

    template复用 extends block include render 参考:https://code.ziqiangxuetang.com/django/django-template.ht ...

  3. IIS设置文件 Robots.txt 禁止爬虫

    robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: value.常见的规则行:User-A ...

  4. 我的Android进阶之旅------>解决Jackson等第三方转换Json的开发包在开启混淆后转换的实体类数据都是null的bug

    1.错误描述 今天测试人员提了一个bug,说使用我们的app出现了闪退的bug,后来通过debug断点调试,发现我们的app转换服务器发送过来的json数据后,都是为null.而之前已经提测快一个月的 ...

  5. Webbench进行网站压力测试

    今天突然发现一个新大陆,Webbench,是linux下,用这很方便,开源,不限制并发访问次数和时间....大爱啊! 下载Webbench 使用wget  或者windows下载好导入linux也行, ...

  6. SIP穿越NAT SIP穿越防火墙-SBC

    FireWall&NAT FireWall是一种被动网络安全防卫技术,位于网络的边界.在两个网络之间运行訪问控制策略.防止外部网络对内部信息资源的非法訪问,也能够阻止特定信息从内部网络被非法输 ...

  7. linux命令行与shell脚本编程 -----15控制脚本

    常见的Linux系统信号 信号 值 描述 1 SIGHUP 挂起进程 2 SIGINT 终止进程 3 SIGQUIT 停止进程 9 SIGKILL 无条件终止进程 15 SIGTERM 可能的话终止进 ...

  8. Canvas:技术小结

    Canvas:技术小结 资料 [教程:MDN官方中文教程] https://developer.mozilla.org/zh-CN/docs/Web/API/Canvas_API/Tutorial [ ...

  9. form:checkboxes radiobutton select用法

    <form:checkboxes path="subjects" items="${requestScope.subjects}" element=&qu ...

  10. linux命令详解之(at)--6/24

    在Linux下,有两个命令可以用来作为计划任务而执行,at:一次性定时任务计划执行crontab :每天定时任务计划执行 以下仅说一下一次性任务计划执行(at)要使用一次性任务计划,linux必须要有 ...