NOIP2014-7-7模拟赛
1.无线通讯网(wireless.pas/cpp/c)
【题目描述】
国防部计划用无线网络连接若干个边防哨所。2种不同的通讯技术用来搭建无线网络;每个边防哨所都要配备无线电收发器;有一些哨所还可以增配卫星电话。
任意两个配备了一条卫星电话线路的哨所(两边都拥有卫星电话)均可以通话,无论他们相距多远。而只通过无线电收发器通话的哨所之间的距离不能超过D,这是受收发器的功率限制。收发器的功率越高,通话距离D会更远,但同时价格也会更贵。
收发器需要统一购买和安装,所以全部哨所只能选择安装一种型号的收发器。换句话说,每一对哨所之间的通话距离都是同一个D。
你的任务是确定收发器必须的最小通话距离D,使得每一对哨所之间至少有一条通话路径(直接的或者间接的)。
【输入格式】 wireless.in
第1行:2个整数S(1<=S<=100)和P(S<P<=500),S表示可安装的卫星电话的哨所数,P表示边防哨所的数量。
接下里P行,每行描述一个哨所的平面坐标(x,y),以km为单位,整数,0<=x,y<=10000。
【输出格式】 wireless.out
第1行:1个实数D,表示无线电收发器的最小传输距离。精确到小数点后两位。
【样例输入】
2 4
0 100
0 300
0 600
150 750
【样例输出】
212.13
数据范围
对于20%的数据 P=2,S=1
对于另外20%的数据 P=4,S=2
对于100%的数据 1<=S<=100,S<P<=500
2.混合图(dizzy.pas/cpp/c)
【题目描述】
Hzwer神犇最近又征服了一个国家,然后接下来却也遇见了一个难题。
Hzwer的国家有n个点,m条边,而作为国王,他十分喜欢游览自己的国家。他一般会从任意一个点出发,随便找边走,沿途欣赏路上的美景。但是我们的Hzwer是一个奇怪的人,他不喜欢走到自己以前走过的地方,他的国家本来有p1条有向边,p2条无向边,由于国王奇怪的爱好,他觉得整改所有无向边,使得他们变成有向边,要求整改完以后保证他的国家不可能出现从某个地点出发顺着路走一圈又回来的情况。(注:m=p1+p2.)
概述:给你一张混合图,要求你为无向图定向,使得图上没有环。
【输入格式】 dizzy.in
第一行3个整数 n,p1,p2,分别表示点数,有向边的数量,无向边的数量。
第二行起输入p1行,每行2个整数 a,b 表示a到b有一条有向边。
接下来输入p2行,每行2个整数 a,b 表示a和b中间有一条无向边。
【输出格式】 dizzy.out
对于每条无向边,我们要求按输入顺序输出你定向的结果,也就是如果你输出a b,那表示你将a和b中间的无向边定向为a->b。
注意,也许存在很多可行的解。你只要输出其中任意一个就好。
【样例输入】
4 2 3
1 2
4 3
1 3
4 2
3 2
【样例输出】
1 3
4 2
2 3
数据范围
对于20%的数据 n<=10 p1<=10 p2<=5
对于30%的数据 n<=10 p1<=30 p2<=20
对于100%的数据 n<=100000 p1<=100000 p2<=100000
数据保证至少有一种可行解。
3.小K的农场(farm.pas/cpp/c)
【题目描述】
小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述:农场a比农场b至少多种植了c个单位的作物,农场a比农场b至多多种植了c个单位的作物,农场a与农场b种植的作物数一样多。但是,由于小K的记忆有些偏差,所以他想要知道存不存在一种情况,使得农场的种植作物数量与他记忆中的所有信息吻合。
【输入格式】 farm.in
第一行包括两个整数n和m,分别表示农场数目和小K记忆中的信息数目。
接下来m行:
如果每行的第一个数是1,接下来有3个整数a,b,c,表示农场a比农场b至少多种植了c个单位的作物。
如果每行的第一个数是2,接下来有3个整数a,b,c,表示农场a比农场b至多多种植了c个单位的作物。
如果每行第一个数是3,家下来有2个整数a,b,表示农场a终止的数量和b一样多。
【输出格式】 farm.out
如果存在某种情况与小K的记忆吻合,输出“Yes”,否则输出“No”。
【样例输入】
3 3
3 1 2
1 1 3 1
2 2 3 2
【样例输出】
Yes
样例解释:三个农场种植数量可以为(2,2,1)。
对于100%的数据 1<=n,m,a,b,c<=10000.
T1:
最小生成树or二分并查集
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#define MAXN 505
using namespace std;
struct Point{
double X,Y;
};
int S,V;
double d[MAXN][MAXN];
vector<double> s;
Point p[MAXN];
int f[MAXN];
int find(int x){
return (f[x]==x)?x:(f[x]=find(f[x]));
}
void lik(int x,int y){
x=find(x),y=find(y);
if(x!=y){
f[x]=y;
}
}
bool check(double c){
for(int i=;i<=V;i++){
f[i]=i;
}
for(int i=;i<=V;i++){
for(int j=i+;j<=V;j++){
if(d[i][j]<=c){
lik(i,j);
}
}
}
int b[MAXN]={};
int cnt=;
for(int i=;i<=V;i++){
int x=find(i);
if(!b[x]){
b[x]=;
cnt++;
}
}
return (cnt<=S);
}
int main()
{
// freopen("data.in","r",stdin);
scanf("%d%d",&S,&V);
for(int i=;i<=V;i++){
scanf("%lf%lf",&p[i].X,&p[i].Y);
}
for(int i=;i<=V;i++){
for(int j=i+;j<=V;j++){
double x1=p[i].X,y1=p[i].Y;
double x2=p[j].X,y2=p[j].Y;
d[i][j]=d[j][i]=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
s.push_back(d[i][j]);
}
}
sort(s.begin(),s.end());
int L=,R=s.size()-;
while(R-L>){
int mid=(L+R)/;
double c=s[mid];
if(check(c)){
R=mid;
}
else{
L=mid+;
}
}
if(check(s[L]))
printf("%.2f\n",s[L]);
else
printf("%.2f\n",s[R]);
return ;
}
Code1-1
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 505
using namespace std;
struct Edge{
int x,y;
double Val;
Edge(int p1=,int p2=,double p3=){
x=p1,y=p2,Val=p3;
}
friend bool operator < (const Edge &p1,const Edge &p2){
return (p1.Val<p2.Val);
}
};
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if('-'==ch)f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int s,n,cnt;
Edge p[MAXN*MAXN];
int X[MAXN],Y[MAXN];
int f[MAXN];
double dist(int a,int b){
double x1=X[a],y1=Y[a];
double x2=X[b],y2=Y[b];
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
int find(int x){
return (f[x]==x)?x:(f[x]=find(f[x]));
}
int main()
{
// freopen("data.in","r",stdin);
s=read();n=read();
for(int i=;i<=n;i++){
f[i]=i;
}
for(int i=;i<=n;i++){
X[i]=read();
Y[i]=read();
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
p[++cnt]=Edge(i,j,dist(i,j));
}
}
sort(p+,p+cnt+);
int t=;
int i;
for(i=;i<=cnt;i++){
int x=p[i].x,y=p[i].y;
x=find(x),y=find(y);
if(x!=y){
f[x]=y; t++;
}
if(t+s==n){
break;
}
}
printf("%.2f\n",p[i].Val);
return ;
}
Code1-2
T2:
拓扑排序
//尚未测评(SJ)
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#define MAXN 100005
using namespace std;
int n,p1,p2;
int first1[MAXN],Next1[MAXN],to1[MAXN],cnt1;
int degree[MAXN];
int b[MAXN];
vector<int> vs;
int pre[MAXN];
void Add1(int x,int y){
Next1[++cnt1]=first1[x];first1[x]=cnt1;to1[cnt1]=y;
}
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if('-'==ch)f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void dfs(int x){
b[x]=;
vs.push_back(x);
for(int e=first1[x];e;e=Next1[e]){
int y=to1[e];
if(!b[y]){
dfs(y);
}
}
}
int main()
{
// freopen("data.in","r",stdin);
n=read();p1=read();p2=read();
for(int i=;i<=p1;i++){
int x,y;
x=read();y=read();
Add1(x,y);
degree[y]++;
}
for(int i=;i<=n;i++){
if(!degree[i]){
dfs(i);
}
}
for(int i=;i<vs.size();i++){
int x=vs[i];
pre[x]=i;
}
for(int i=;i<=p2;i++){
int x,y;
x=read();y=read();
if(pre[x]<pre[y]){
printf("%d %d\n",x,y);
}
else{
printf("%d %d\n",y,x);
}
}
return ;
}
Code2
T3:
差分+正环判断
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define MAXN 10005
using namespace std;
int first[MAXN],Next[MAXN*],to[MAXN*],Val[MAXN*],cnt;
int n,m;
int b[MAXN],d[MAXN];
void Add(int x,int y,int w){
Next[++cnt]=first[x];first[x]=cnt;to[cnt]=y;Val[cnt]=w;
}
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if('-'==ch)f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int SPFA(int x){
if(b[x]){
return ;
}
b[x]=;
for(int e=first[x];e;e=Next[e]){
int y=to[e],w=Val[e];
if(d[y]<d[x]+w){
d[y]=d[x]+w;
if(SPFA(y))
return ;
}
}
b[x]=;
return ;
}
int main()
{
// freopen("data.in","r",stdin);
n=read();
m=read();
for(int i=;i<=m;i++){
int p=read();
if(==p){
int x=read(),y=read(),w=read();
Add(x,y,w);
}
else if(==p){
int x=read(),y=read(),w=read();
Add(y,x,-w);
}
else{
int x=read(),y=read();
Add(x,y,);
Add(y,x,);
}
}
for(int i=;i<=n;i++){
memset(d,,sizeof(d));
if(SPFA(i)){
printf("No\n");
return ;
}
}
printf("Yes\n");
return ;
}
Code3
最新文章
- SQL 常用操作
- ThinkPHP 自动验证相关注意
- Theano2.1.14-基础知识之理解为了速度和正确性的内存别名
- 基于MATLAB的GUI(Graphical User Interface)音频实时显示设计
- Windows无法安装到GPT分区形式磁盘的解决办法
- XStream的例子
- 基于ace后台管理系统模板--CMS(Thinkphp框架)的筹划
- android中获取打气筒的几种方式
- 畅谈Spring设计哲学
- ORACLE查询数据库的锁表情况
- Linux 下配置 SoftEther Client
- mysql xtrabackup增量备份
- CXF-02: 使用CXF处理JavaBean式的复合类型和List集合类型
- QT 设计师使用样式表添加背景
- nodejs+express blog项目分享
- AspnetCore WebApi使用Swagger简单入门
- Thing in java 第5章,初始化和清理,练习题答案
- [纪录片] 鸟瞰中国 ——China from Above
- 记录Ok6410 sd 启动uboot
- [转]Windows下配置Node.js和Cordova