ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2022/6/29随笔

2022-06-29 21:33:34  阅读:125  来源: 互联网

标签:std 10 随笔 int 29 2022 using include foor


今天状态比较差,数量比较少,题解也看了很多

//P5143 攀爬者

P5143 攀爬者 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cmath> 
 4 #include<stdio.h>
 5 using namespace std;
 6 const int maxn=5e4+10;
 7 int n;
 8 double s=0;
 9 struct node
10 {
11     int x,y,z;
12 }a[maxn];
13 bool cmp(node x,node y)
14 {
15     return x.z<y.z;
16 }
17 int main()
18 {
19     cin>>n;
20     for(int i=1;i<=n;i++)
21     {
22         cin>>a[i].x>>a[i].y>>a[i].z;
23     }
24     sort(a+1,a+n+1,cmp);
25     for(int i=1;i<=n-1;i++)
26     {
27         s+=sqrt(pow(a[i].x-a[i+1].x,2)+pow(a[i].y-a[i+1].y,2)+pow(a[i].z-a[i+1].z,2));
28     }
29     printf("%.3f\n",s);
30     return 0;
31  } 

 

 

//P1104 生日

P1104 生日 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 struct node
 5 {
 6     int id;
 7     string str;
 8     int y,m,d;
 9 }a[110];
10 int n;
11 bool cmp(node x,node y)
12 {
13     if(x.y!=y.y) return x.y<y.y;
14     else if(x.m!=y.m) return x.m<y.m;
15     else if(x.d!=y.d) return x.d<y.d;
16     else return x.id>y.id;
17 }
18 int main()
19 {
20     cin>>n;
21     for(int i=1;i<=n;i++)
22     {
23         a[i].id=i;
24         cin>>a[i].str>>a[i].y>>a[i].m>>a[i].d;
25     }
26     sort(a+1,a+n+1,cmp);
27     for(int i=1;i<=n;i++)
28     {
29         cout<<a[i].str<<endl;
30      } 
31      return 0;
32 }

 

 

 //P1012 [NOIP1998 提高组] 拼数

P1012 [NOIP1998 提高组] 拼数 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 int n;
 5 string str[25];
 6 //神来之笔,有效果解决了361>36从而导致:36136的问题 
 7 bool cmp(string x,string y)
 8 {
 9     return x+y>y+x;
10 }
11 int main()
12 {
13     cin>>n;
14     for(int i=0;i<n;i++)
15     {
16         cin>>str[i];
17     }
18     sort(str,str+n,cmp);
19     for(int i=0;i<n;i++)
20     {
21         cout<<str[i];
22     }
23     return 0;
24 }

 

 

//P2241 统计方形(数据加强版)

P2241 统计方形(数据加强版) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

m*n区域中
能找出的所有矩形个数(长方形+正方形)为
(1+2+3+……n)*(1+2+3+……m)=((1+n)*(1+m)*n*m)/4(等差数列求和)

边长为1 个数n*m

边长为2 个数(n-1)*(m-1)

边长为3 个数(n-2)*(m-2)

所以 边长为min{n,m} 个数:(m-min{n,m}+1)*(n-min{n,m}+1)

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 #define ll long long
 5 ll s,z=0,n,m;
 6 int main()
 7 {
 8     cin>>n>>m;
 9     s=((1+n)*(1+m)*n*m)/4;
10     for(int i=1;i<=min(n,m);i++)
11     {
12         z+=(n-i+1)*(m-i+1);
13     }
14     cout<<z<<" "<<s-z<<endl;
15     return 0;
16 }

 

 

//P2089 烤鸡

P2089 烤鸡 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

写了两个十层的循环,实际上只运行了60次

1s内for的最大循环次数大概是1.2e8 

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<stdio.h>
 4 using namespace std;
 5 #define foor(i,a,b) for(int i=a;i<=b;i++)
 6 int n,ans=0;
 7 int main()
 8 {
 9     int a,b,c,d,e,f,g,h,i,j;
10     cin>>n;
11     foor(a,1,3)
12     foor(b,1,3)
13     foor(c,1,3)
14     foor(d,1,3)
15     foor(e,1,3)
16     foor(f,1,3)
17     foor(g,1,3)
18     foor(h,1,3)
19     foor(i,1,3)
20     foor(j,1,3)
21     {
22         if(a+b+c+d+e+f+g+h+i+j==n) ans++;
23     }
24     cout<<ans<<endl;
25     foor(a,1,3)
26     foor(b,1,3)
27     foor(c,1,3)
28     foor(d,1,3)
29     foor(e,1,3)
30     foor(f,1,3)
31     foor(g,1,3)
32     foor(h,1,3)
33     foor(i,1,3)
34     foor(j,1,3)
35     {
36         if(a+b+c+d+e+f+g+h+i+j==n)
37         {
38             printf("%d %d %d %d %d %d %d %d %d %d\n",a,b,c,d,e,f,g,h,i,j);
39         }
40     }
41     return 0;
42 }

 

 

//P1618 三连击(升级版)

P1618 三连击(升级版) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

 1 //先有一个数,按照比例关系推另外两个数,然后根据题意进行判断(三位数,1-9组合)
 2 //a:b:c=A:B:C(A,B,C为常数)
 3 //则:b=a*B/A(B为整数)
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 int a,b,c,A,B,C,flag=0;
 8 bool z[15];
 9 void go(int x)
10 {
11     z[x%10]=true;
12     z[x/10%10]=true;
13     z[x/100%10]=true;
14 }
15 bool check(int a,int b,int c)
16 {
17     fill(z,z+15,false);
18     if(b>999|c>999) return false;
19     go(a);go(b);go(c);
20     for(int i=1;i<=9;i++)
21     {
22         if(!z[i])
23         return false;
24     }
25     return true;
26 }
27 int main()
28 {
29     cin>>A>>B>>C;
30     for(int i=123;i<=789;i++)
31     {
32         if(i*B%A!=0||i*C%A!=0) continue;//b,c不是整数,不合题意 
33         b=i*B/A;
34         c=i*C/A;
35         if(check(i,b,c))
36         {
37             cout<<i<<" "<<b<<" "<<c<<" "<<endl;
38             flag=1;
39         }
40     }
41     if(flag==0)
42     cout<<"No!!!"<<endl;
43     return 0;
44 }

 

标签:std,10,随笔,int,29,2022,using,include,foor
来源: https://www.cnblogs.com/inawaken/p/16424997.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有