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

会有一股神秘感。 提交于 2020-01-17 12:57:30

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!