A:

水题

代码:

 #include<cstdio>
#include<algorithm>
using namespace std; int she[]; int n,m,c; int main()
{
int ca=,a;
while(scanf("%d%d%d",&n,&m,&c)&&(n+m+c))
{
printf("Sequence %d\n",ca++);
for(int i=; i<=n; i++)
scanf("%d",&she[i]);
int ans=,ma=;
while(m--)
{
scanf("%d",&a);
ans+=she[a];
ma=max(ma,ans);
she[a]=-she[a];
}
if(ma>c)puts("Fuse was blown.");
else
{
puts("Fuse was not blown.");
printf("Maximal power consumption was %d amperes.\n",ma);
}
puts("");
}
return ;
}

B:

模拟;

代码:

 #include<cstdio>
#include<cstring>
#include<queue>
#define maxn 55
using namespace std; bool map[maxn][maxn]; int n,flag; struct node
{
int x,y;
}; queue<node>q; void move(char s)
{
node cur=q.back();
node next=q.front();
q.pop();
map[next.x][next.y]=;
if(s=='E')
{
next.x=cur.x;
next.y=cur.y+;
}
else if(s=='N')
{
next.x=cur.x-;
next.y=cur.y;
}
else if(s=='W')
{
next.x=cur.x;
next.y=cur.y-;
}
else if(s=='S')
{
next.x=cur.x+;
next.y=cur.y;
}
if(map[next.x][next.y]==)
{
flag=;
return;
}
else if(next.x<=||next.x>||next.y<=||next.y>)
{
flag=-;
return;
}
else
{
q.push(next);
map[next.x][next.y]=;
}
} char s[];
int main()
{
while(scanf("%d",&n)&&n)
{
node no;
flag=;
memset(map,,sizeof map);
while(!q.empty())q.pop();
for(int i=; i<=; i++)
{
no.x=;
no.y=i;
map[][i]=;
q.push(no);
}
scanf("%s",s);
int i;
for(i=; i<n; i++)
{
move(s[i]);
if(flag<)break;
}
if(flag==)printf("The worm successfully made all %d moves.\n",n);
else if(flag==-)printf("The worm ran off the board on move %d.\n",i+);
else if(flag==)printf("The worm ran into itself on move %d.\n",i+);
}
return ;
}

C:

我用的是bfs;

代码:

 #include<cstdio>
#include<queue>
#include<vector>
#define maxn 10005
using namespace std; vector<int>ve[maxn];
int di[maxn];
queue<int>q;
int main()
{
int n,x;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&x);
ve[x].push_back(i);
}
int l=ve[].size();
for(int i=;i<l;i++)
{
q.push(ve[][i]);
di[ve[][i]]=;
}
while(!q.empty())
{
int cur=q.front();
q.pop();
l=ve[cur].size();
for(int i=;i<l;i++)
{
q.push(ve[cur][i]);
di[ve[cur][i]]=di[cur]+;
}
}
int ans=;
for(int i=;i<=n;i++)
if(ans<di[i])ans=di[i];
printf("%d\n",ans);
}

D:

dfs;

我先用一个表来存,一直都是T;

没想到用状态压缩就可以过了;

代码:

 #include<cstdio>
#include<vector>
#define maxn 23
using namespace std; vector<int>ve[maxn];
int n,s,m; bool dfs(int x,int t)
{
if(t==s)return x==n-;
int l=ve[x].size();
for(int i=;i<l;i++)
{
int a=ve[x][i];
if(~(t>>a)&)
if(dfs(a,t|(<<a)))
return ;
}
return ;
} int main()
{
int x,y;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
ve[i].clear();
for(int i=;i<m;i++)
{
scanf("%d%d",&x,&y);
x--,y--;
ve[x].push_back(y);
ve[y].push_back(x);
}
s=(<<n)-;
if(dfs(,))puts("");
else puts("");
}
return ;
}

ACM俱乐部算法基础练习赛(1)的更多相关文章

  1. Levenberg-Marquardt算法基础知识

    Levenberg-Marquardt算法基础知识 (2013-01-07 16:56:17) 转载▼   什么是最优化?Levenberg-Marquardt算法是最优化算法中的一种.最优化是寻找使 ...

  2. acm常见算法及例题

    转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题  初期:一.基本算法:     (1)枚举. (poj17 ...

  3. ACM常用算法及练习(2)

    ACM常用算法及练习 知识类型 重要度 容易度 应掌握度 典型题 其他           数据结构(5) 链表 ★★☆ ★★★ ★★☆     栈 stack ★★★ ★★★ ★★★ HLoj120 ...

  4. ACM常用算法及练习(1)

    ACM常用算法及练习 第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打出来. 1.最短 ...

  5. 解读Raft(一 算法基础)

    最近工作中讨论到了Raft协议相关的一些问题,正好之前读过多次Raft协议的那paper,所以趁着讨论做一次总结整理. 我会将Raft协议拆成四个部分去总结: 算法基础 选举和日志复制 安全性 节点变 ...

  6. 腾讯2017年暑期实习生编程题【算法基础-字符移位】(C++,Python)

     算法基础-字符移位 时间限制:1秒 空间限制:32768K 题目: 小Q最近遇到了一个难题:把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间. 你能帮帮小Q吗? ...

  7. 算法基础_递归_求杨辉三角第m行第n个数字

    问题描述: 算法基础_递归_求杨辉三角第m行第n个数字(m,n都从0开始) 解题源代码(这里打印出的是杨辉三角某一层的所有数字,没用大数,所以有上限,这里只写基本逻辑,要符合题意的话,把循环去掉就好) ...

  8. ACM主要算法

    ACM主要算法ACM主要算法介绍 初期篇 一.基本算法(1)枚举(poj1753, poj2965)(2)贪心(poj1328, poj2109, poj2586)(3)递归和分治法(4)递推(5)构 ...

  9. 毕业设计预习:SM3密码杂凑算法基础学习

    SM3密码杂凑算法基础学习 术语与定义 1 比特串bit string 由0和1组成的二进制数字序列. 2 大端big-endian 数据在内存中的一种表示格式,规定左边为高有效位,右边为低有效位.数 ...

随机推荐

  1. 使用Netty进行Android与Server端通信实现文字发送接收与图片上传

    ANOTHER TITLE: Let’s use netty to achieve text send and receive and  image transfer to server based ...

  2. mysql中查询某字段所在的表方法

    select TABLE_NAME from information_schema.COLUMNS where COLUMN_NAME = 'type'

  3. JVM笔记3:Java垃圾收集算法与垃圾收集器

    当前商业虚拟机的垃圾收集都采用"分代收集"算法,即根据对象生命周期的不同,将内存划分几块,一般为新生代和老年代,不同的代根据其特点使用最合适的垃圾收集算法 一,标记-清除算法: 该 ...

  4. hdu 2027 统计元音

    统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. SharePoint 页面Pages和SitePages目录创建不成功解决

    最近项目中要用到Pages及SitePages目录中的一个 可是目录时,不是发现没有Pages就是没SitePages: 分析后才得知Pages目录需要开户SharePoint Server Publ ...

  6. 20160324 javaweb 之request

    package com.dzq.servlet; import java.io.IOException; import javax.servlet.ServletException; import j ...

  7. 关于block块使用的6点注意事项

    对于刚学习OC新伙伴,block块一直都是一个比较纠结.比较难懂的知识点,不过,在使用一段时间后,就会感觉很酸爽.block块的原理及使用我就不再赘述,网上有很多这方面的资料.我个人使用这么长时间以来 ...

  8. ReactiveCocoa 入门学习 (一)

    引言 现在由于需求的不断发展,MVC这个经典的框架由于Controller的任务越来越多,显得"臃肿"了,网上又推出了新的框架,比如MVVM,ReactiveCocoa, 今天就来 ...

  9. Ibatis学习记录

    几大要素:1.jdbc.properties //数据库连接配置2.SqlMapContext.xml //主配置文件3.user_SqlMap.xml //映射文件4.三层框架 创建Ibatis工程 ...

  10. Installshield: custom action return value

    参考:MSDN: Custom Action Return Values 参考:MSDN: Logging of Action Return Values