首页 > 其他 > 详细

[蓝桥杯2015初赛]方程整数解 unordered_map

时间:2020-01-17 12:20:04      阅读:189      评论:0      收藏:0      [点我收藏+]

unordered_map:

如果直接写报错加上tr1:

1 #include<tr1/unordered_map>//注意写法 
2 using namespace std;
3 using namespace std::tr1;//注意写法 

std::unorederd_map 是一个关联容器,其中的元素根据键来引用,而不是根据索引来引用。

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <queue>
 4 #include <cstdio>
 5 #include<tr1/unordered_map>//注意写法 
 6 using namespace std;
 7 using namespace std::tr1;//注意写法 
 8 int a,b,c;
 9 
10 int main()
11 {
12     int n;
13     while(~scanf("%d",&n))
14     {
15         int cnt=0;
16         int cntc=0;
17         unordered_map<int,int> mp;
18         for(int i=1;i*i<=n;i++)
19         {
20             int t=i*i;
21             if(mp.count(t)==0)
22                 mp[t]=i;
23         }
24         for(int i=1;i*i<=n;i++)
25         {
26             for(int j=1;j*j<=n;j++)
27             {
28                 int t=n-i*i-j*j;
29                 if(mp.count(t)&&i<=j&&j<=mp[t])
30                 {
31                         cnt++;
32                     printf("%d %d %d\n",i,j,mp[t]);
33                 }
34             }
35         }
36         if(cnt==0)
37         {
38             printf("No Solution\n");
39         }
40     }
41     return 0;
42 }

思路来自:https://www.cnblogs.com/luyuan-chen/p/12202059.html

[蓝桥杯2015初赛]方程整数解 unordered_map

原文:https://www.cnblogs.com/fudanxi/p/12205075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!