当前位置: 首页 > news >正文

博罗企业网站建设硬件工程师都没人干了

博罗企业网站建设,硬件工程师都没人干了,宁波网站建设公司名单推荐,科技广告公司网站建设题目描述#xff1a;给出n棵树的高度#xff0c;每棵树上都站着一只鸟#xff0c;枪手Jack站在最左边那棵树的左边对鸟进行射击#xff0c;当Jack在高度为H的地方向右发射一颗子弹的时候#xff0c;高度为H的树上的鸟儿就会掉落#xff08;注#xff1a;其他树上的鸟儿不…题目描述给出n棵树的高度每棵树上都站着一只鸟枪手Jack站在最左边那棵树的左边对鸟进行射击当Jack在高度为H的地方向右发射一颗子弹的时候高度为H的树上的鸟儿就会掉落注其他树上的鸟儿不会飞走或掉落这不是脑经急转弯。Jack会射击多次他想知道每次射击会有多少鸟儿掉落下来。 思路题意十分清晰思路也很简单只要实现这种映射关系就行了数据量比较大。 方法1mapIO外挂水之 1 #include cstdio2 #include cctype3 #include map4 using namespace std;5 6 mapint, int mp;7 int n, m, tmp;8 char buffer[10];9 10 void print_d( int x ) 11 { 12 if ( x 0 ) 13 { 14 putchar(0); 15 } 16 else 17 { 18 int p 0; 19 while ( x ) 20 { 21 buffer[p] x % 10 0; 22 x x / 10; 23 } 24 for ( int i p - 1; i 0; i-- ) 25 { 26 putchar(buffer[i]); 27 } 28 } 29 putchar(\n); 30 } 31 32 void scan_d( int x ) 33 { 34 char ch getchar(); 35 while ( !isdigit(ch) ) ch getchar(); 36 x 0; 37 do 38 { 39 x x * 10 ch - 0; 40 ch getchar(); 41 } while ( isdigit(ch) ); 42 } 43 44 int main () 45 { 46 while ( scanf(%d%d, n, m) ! EOF ) 47 { 48 mp.clear(); 49 while ( n-- ) 50 { 51 scan_d(tmp); 52 mp[tmp]; 53 } 54 while ( m-- ) 55 { 56 scan_d(tmp); 57 print_d(mp[tmp]); 58 mp[tmp] 0; 59 } 60 } 61 return 0; 62 } 这样写完全是对的不过比csc的代码要慢一点原因如下 当调用mp[tmp]的时候如果tmp在map中不存在则默认会插入一个tmp到0的映射然后返回所以这样写会让节点数增多查询效率变低。 证明代码如下 1 #include iostream2 #include cstdlib3 #include map4 using namespace std;5 6 int main ()7 {8 mapint, int mp;9 cout mp is empty: mp.size() endl; 10 cout mp[111] endl; 11 cout The size is: mp.size() endl; 12 cout mp[222] endl; 13 cout The size is: mp.size() endl; 14 for ( mapint, int::iterator it mp.begin(); it ! mp.end(); it ) 15 { 16 cout it-first maps into it-second endl; 17 } 18 system(pause); 19 return 0; 20 } 运行结果如下 可见确实是这样因此可以这样写来加快效率 1 #include cstdio2 #include map3 using namespace std;4 5 mapint, int mp;6 int n, m, tmp;7 8 int main ()9 { 10 while ( scanf(%d%d, n, m) ! EOF ) 11 { 12 mp.clear(); 13 while ( n-- ) 14 { 15 scanf(%d, tmp); 16 mp[tmp]; 17 } 18 while ( m-- ) 19 { 20 scanf(%d, tmp); 21 if ( mp.count(tmp) ) 22 { 23 printf(%d\n, mp[tmp]); 24 mp.erase(tmp); 25 } 26 else 27 { 28 printf(0\n); 29 } 30 } 31 } 32 return 0; 33 } 不过实测差不多关键可能还是hdu服务器不稳定吧不过mp[tmp] 0; 还是没有 mp.erase(tmp); 好前者删除节点后者只是修改映射的值前者配合mp.count(tmp)理论上更胜一筹。 方法2二分 略... 方法3hash 1 #include cstdio2 #include cstring3 using namespace std;4 5 const int N 5000007;6 int hash_table[N];7 int cnt[N];8 int n, m, tmp;9 10 int hash_key( int key ) 11 { 12 return key % N; 13 } 14 15 int kth( int k ) 16 { 17 int r ( k 1 ) 1; 18 if ( k 1 ) return r * r; 19 return -r * r; 20 } 21 22 void insert( int key ) 23 { 24 int t hash_key(key); 25 for ( int i 0; ; i ) 26 { 27 int pos t kth(i); 28 if ( pos 0 ) pos N; 29 if ( pos N ) pos - N; 30 if ( hash_table[pos] -1 ) 31 { 32 hash_table[pos] key; 33 cnt[pos]; 34 return ; 35 } 36 else if ( hash_table[pos] key ) 37 { 38 cnt[pos]; 39 return ; 40 } 41 } 42 } 43 44 int find( int key ) 45 { 46 int t hash_key(key); 47 for ( int i 0; ; i ) 48 { 49 int pos t kth(i); 50 if ( pos 0 ) pos N; 51 if ( pos N ) pos - N; 52 if ( hash_table[pos] key ) 53 { 54 int r cnt[pos]; 55 cnt[pos] 0; 56 return r; 57 } 58 else if ( hash_table[pos] -1 ) 59 { 60 return 0; 61 } 62 } 63 } 64 65 int main () 66 { 67 while ( scanf(%d%d, n, m) ! EOF ) 68 { 69 memset( hash_table, -1, sizeof(hash_table) ); 70 memset( cnt, 0, sizeof(cnt) ); 71 while ( n-- ) 72 { 73 scanf(%d, tmp); 74 insert(tmp); 75 } 76 while ( m-- ) 77 { 78 scanf(%d, tmp); 79 printf(%d\n, find(tmp)); 80 } 81 } 82 return 0; 83 }  转载于:https://www.cnblogs.com/huoxiayu/p/4393062.html
http://www.pierceye.com/news/382021/

相关文章:

  • 0基础学做网站什么做网站做个网站一般要多少钱啊
  • 外贸营销型网站建设多少钱wordpress付费浏览
  • 网站空间可以换吗进网站备案
  • 番禺建设网站开发软件工程专业介绍
  • 如何做网站定位网站建设报价新鸿儒
  • 商务网站建设包含了河北招投标公共服务平台
  • 高权重网站怎么发软文外贸平台app
  • nas服务器 做网站网页设计页面图片
  • 青海建设协会网站电子商务网站备案
  • 性价比高的广州网站建设不同用户入口的网站样板
  • 投资交易网站开发黑镜wordpress主题破解
  • 文化传媒公司网站建设西渡网站建设
  • 购物网站为什么做移动端seo优化快速排名
  • iis服务器网站301重定向怎么做国家企业信息公开网查询系统
  • 免费家具网站模板做网站去什么公司好
  • 五个网站南宁网页制作培训
  • 枣庄建设网站wordpress如何自己编辑
  • 河南省城乡住房建设厅网站首页哪个公司网站备案快
  • 湘潭做网站价格优选磐石网络微信里怎么进入自己的公众号
  • 孟州网站wordpress主题游戏cms
  • 用php做的网站怎么上传莱州教体局网站
  • 网站互动性无锡模板建站
  • 中铁十六局工资明细沧州网站seo公司
  • 北京网站建设软件网页制作自我介绍源代码
  • 怎么注册公司的网站免费可以做旅游海报 的网站
  • 贵阳网站建设包首页微商建立网站
  • ppt制作软件全模板免费大连seo网站管理
  • 网站门户设计设计师的网站有哪些
  • 旅游公司网站建设百度一下官方下载安装
  • 网站上传大马后怎么做宁波seo推广公司电话