杭电多校训练第一场

第一题:http://acm.hdu.edu.cn/showproblem.php?pid=6298

注意:题目中的x|n代表的意思是n能被x整除。

题目的意思是:给你一个整数n,寻找x,y,z,使得x+y+z=n并且x|n,y|n,z|n,求xyz的最大值。

可以证明,如果n是3的倍数,当x=y=z=n/3时,有最大值;如果n是4的倍数,当x=y=n/4,z=n/2时有最大值;否则没有符合条件的x,y,z

特别注意:用cin,cout会超时

 1 #include <iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 typedef long long ll;
 5 ll n,t,x;
 6 int main()
 7 {
 8     scanf("%lld",&t);
 9     while(t--)
10     {
11         scanf("%lld",&n);
12         if(n%3!=0)
13         {
14             if(n%4==0)
15             {
16 //                cout<<n*n*n/32<<endl;
17                 printf("%lld\n",n*n*n/32);
18             }
19             else
20                 printf("-1\n");
21         }
22         else
23         {
24 //            cout<<n*n*n/27<<endl;
25             printf("%lld\n",n*n*n/27);
26         }
27     }
28     return 0;
29 }
View Code

第十一题:http://acm.hdu.edu.cn/showproblem.php?pid=6308

时间转化问题

提取字符串中的数字时,不能直接提取,要特别注意数字是两位数以上的情况!

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 int t,a,b;
 7 char s[20];
 8 int main()
 9 {
10     scanf("%d",&t);
11     while(t--)
12     {
13         scanf("%d %d",&a,&b);
14         scanf("%s",s);
15         int len=strlen(s);
16         if(len==5)
17         {
18             int c=s[4]-'0';
19             if(s[3]=='-')
20             {
21                 c=-c;
22             }
23             c=8-c;
24             a-=c;
25             if(a<0)
26             {
27                 a+=24;
28             }
29             else if(a>=24)
30             {
31                 a-=24;
32             }
33             printf("%02d:%02d\n",a,b);
34         }
35         else if(len==6)
36         {
37             int c=(s[4]-'0')*10+s[5]-'0';
38             if(s[3]=='-')
39             {
40                 c=-c;
41             }
42             c=8-c;
43             a-=c;
44             if(a<0)
45             {
46                 a+=24;
47             }
48             else if(a>=24)
49             {
50                 a-=24;
51             }
52             printf("%02d:%02d\n",a,b);
53         }
54         else
55         {
56             int i=4;
57             int c=0;
58             while(s[i]!='.')
59             {
60                 c=c*10+(s[i]-'0');
61                 i++;
62             }
63             i++;
64             int d=s[i]-'0';
65             d*=6;
66             c*=60;
67             c+=d;
68             a*=60;
69             a+=b;
70             if(s[3]=='-')
71             {
72                 c=-c;
73             }
74             c=480-c;
75             a-=c;
76             if(a<0)
77             {
78                 a+=60*24;
79             }
80             else if(a>=60*24)
81             {
82                 a-=60*24;
83             }
84             printf("%02d:%02d\n",a/60,a%60);
85         }
86     }
87     return 0;
88 }
View Code

第三题:http://acm.hdu.edu.cn/showproblem.php?pid=6300

给你3n个点,输出n个不相交的三角形的顶点坐标

 1 #include <iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 struct node
 5 {
 6     int x,y,pos;
 7 }mp[10005];
 8 int t,n;
 9 bool cmp(node a,node b)
10 {
11     if(a.x==b.x)
12         return a.y<b.y;
13     else
14         return a.x<b.x;
15 }
16 int main()
17 {
18     cin>>t;
19     while(t--)
20     {
21         cin>>n;
22         for(int i=0;i<3*n;i++)
23         {
24             cin>>mp[i].x>>mp[i].y;
25             mp[i].pos=i+1;
26         }
27         sort(mp,mp+3*n,cmp);
28         for(int i=0;i<3*n;i+=3)
29         {
30             cout<<mp[i].pos<<" "<<mp[i+1].pos<<" "<<mp[i+2].pos<<endl;
31         }
32     }
33 //    cout << "Hello world!" << endl;
34     return 0;
35 }
View Code

 

posted @ 2018-07-27 09:52  Scott_Wong  阅读(200)  评论(0)    收藏  举报