2014蓝桥杯编程第一题
来源:互联网 发布:网络安全保密 标准 编辑:程序博客网 时间:2024/05/29 04:38
记录每一时刻蚂蚁的状态,较简单的一题。
#include <cstdio>#include <cmath>#include <iostream>using namespace std;struct T{bool ill;int pos; };T ant[100];int size = 0;int main(){ int n,t; int ans = 0; cin>>n; int total = n; size =n; for(int i=0;i<n;i++){ cin>>t; ant[i].pos = t; if(i==0) ant[i].ill = true; else ant[i].ill = false; } while(total){ for(int i=0;i<size;i++){ if(ant[i].pos>0) ant[i].pos++; else ant[i].pos++; if(abs(ant[i].pos)<0 || abs(ant[i].pos)>100) total--; } for(int i=0;i<size;i++){ for(int j=i+1;j<size;j++){ if(abs(ant[j].pos)==abs(ant[i].pos)){ if(ant[i].ill||ant[j].ill){ ant[i].ill=true; ant[j].ill=true; } ant[j].pos=-ant[j].pos; ant[i].pos=-ant[i].pos; } } } } for(int i=0;i<size;i++){ if(ant[i].ill) ans++; } cout<<ans<<endl; return 0;}
0 0
- 2014蓝桥杯编程第一题
- 编程之美 第一场 第一题
- 金色十月编程第一题
- p243 编程练习第一题
- Java 编程题目 第一题
- 2014 编程之美 资格赛 第一题 同构
- 2014编程之美初赛第一场第二题
- 微软2014在线编程一小时活动第一题
- 程序员互动联盟(第一届编程大赛第一题)
- 2014编程之美初赛第一场
- 编程之美 2014 初赛第一场
- 360笔试编程题之第一题
- 滴滴笔试编程题第一题
- 编程之美大赛资格赛第一题
- 2012届华为编程大赛第一题
- 微软编程之美2015 第一题
- 2015编程之美资格赛第一题
- 2015编程之美资格赛第一题
- iwebpp.io - 利用Node.js发布Peer/P2P风格的Web Service
- 全排列的algorithm调用方法
- ubuntu中安装windows字体,设置myeclpse字体和windows下字体一样
- 一个node.js编写的消息服务器,支持最新的websocket草案
- 图像文件的3种存储形式
- 2014蓝桥杯编程第一题
- mysql高可用各个技术的比较
- Android上ListView的OnItemDoubleClick实现
- JAVA设计模式(二十八)——迪米特法则
- javascript计算浮点数精确计算,java浮点数精确计算
- python中的map/reduce, filter, lambda, set的用法
- 递归 迭代 得到家谱树 子孙树
- 说说内联函数和一般函数
- HDU 1213 How Many Tables 【并查集】