2018 Multi-University Training Contest 1
程序员文章站
2022-06-05 13:09:58
...
1.hdu6298 Maximum Multiple (思维)
题解: n=x+y+z, x∣n, y∣n, z∣n and xyz is maximum ==》x,y,z能被n整除,说明x,y,z都是n的因数,
设r=n/x,s=n/y,t=n/z,则n=n/r+n/s+n/t,即1=1/r+1/s+1/t,r*s*t=s*t+r*t+r*s,
得到满足此条件的解有三组,如下图所示
而第一组解需要满足6|n,第二组4|n,第三组3|n,当x=y=z时,x*y*z值最大,也就是说x,y,z的值越接近,也可以说r,s,t的值越接近,x*y*z的值越大,当然6|n成立的话,3|n肯定成立,舍弃第一组。二三组中优先考虑第三组。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n;
int main(){
long long t;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
if(n%3==0){
printf("%lld\n",n/3*n/3*n/3);
}else if(n%4==0){
printf("%lld\n",n/4*n/4*n/2);
}else printf("-1\n");
}
return 0;
}
2.hdu6299 Balanced Sequence
3.hdu6300 Triangle Partition (思维)
题解:给你3*n个点,任意三个点都不在一条直线上,让你构造n个不相交的三角形,输出这n个三角形的顶点编号。
首先,对横纵坐标进行排序,每三个顶点顺次连接。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1010;
struct Node{
int x,y,id;
bool operator < (const Node &n)const{
if(x!=n.x) return x<n.x;
return y<n.y;
}
}a[3*maxn];
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
n*=3;
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
a[i].id=i;
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
printf("%d",a[i].id);
//cout<<"i%3="<<i%3<<endl;
if(i%3==0){
printf("\n");
}
else printf(" ");
}
}
return 0;
}
当然,也可以用pair来实现,其内部自定义了<运算符。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1010;
pair<pair<int,int>,int > a[3*maxn];
int main(){
int t,n,x,y;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
n*=3;
for(int i=1;i<=n;i++){
scanf("%d%d",&x,&y);
a[i]=make_pair(make_pair(x,y),i);
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
printf("%d",a[i].second);
//cout<<"i%3="<<i%3<<endl;
if(i%3==0){
printf("\n");
}
else printf(" ");
}
}
return 0;
}
4.hdu6301 Distinct Values
5.hdu6302 Maximum Weighted Matching
6.hdu6303 Period Sequence
7.hdu6304 Chiaki Sequence Revisited
8.hdu6305 RMQ Similar Sequence
9.hdu6306 Lyndon Substring
10.hdu6307 Turn Off The Light
11.hdu6308 Time Zone (模拟)
题解:全部转化成分,这题卡精度,注意读入。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int t,a,b;
double c;
char op;
scanf("%d",&t);
while(t--){
scanf("%d%d",&a,&b);
getchar();getchar();getchar();getchar();
scanf(" %c%lf",&op,&c);
//cout<<"op="<<op<<",c="<<c<<endl;;
int d=floor(c*10+0.1); //注意这里:*10转化成整数防止误差,+0.1也是为了防止误差,因为存在浮点误差
if(op=='-')
d*=-1;
int res=a*60-8*60+b+d*6;
res+=60*24;
res%=60*24;
printf("%02d:%02d\n",res/60,res%60);
}
return 0;
}
注意这里sscanf的使用
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
char s[20];
int main(){
int t,a,b;
double c;
char op;
scanf("%d",&t);
while(t--){
scanf("%d%d%s",&a,&b,s);
//cout<<"op="<<op<<",c="<<c<<endl;
op=s[3];
sscanf(s+4,"%lf",&c); //相当于从字符串s[4]的地方开始,以缓冲流的方式读入c
int d=floor(c*10+0.1); //注意这里:*10转化成整数防止误差,+0.1也是为了防止误差,因为存在浮点误差
if(op=='-')
d*=-1;
int res=a*60-8*60+b+d*6;
res+=60*24;
res%=60*24;
printf("%02d:%02d\n",res/60,res%60);
}
return 0;
}
推荐阅读
-
2019 Multi-University Training Contest 2: 1010 Just Skip The Problem 自闭记
-
HDU 6038 Function(找规律)——2017 Multi-University Training Contest - Team 1
-
2020 Multi-University Training Contest 6---- HDU--6836、Expectation(矩阵树)
-
2018 Multi-University Training Contest 6 Werewolf(hdu6370 基环内向树)
-
2018 Multi-University Training Contest 6--HDU 6370 Werewolf(dfs+并查集)
-
2020 Multi-University Training Contest 8---- HDU--6863、Isomorphic Strings(哈希)
-
2018 Multi-University Training Contest 3 C Dynamic Graph Matching(hdu 6321)(状压dp)
-
2018 Multi-University Training Contest 4 B Harvest of Apples(hdu 6333)(莫队)
-
2018 Multi-University Training Contest 7 1011 Swordsman
-
2018 Multi-University Training Contest 1