问题标题: 酷町堂:2705

0
0
已解决
李奕歌
李奕歌
初级天翼
初级天翼

题目描述 Description

某学校要进行重新装潢,一共需要三种不同的材料,现在有多个供应商可以提供所有装潢需要的材料,供应商提供三种材料的价格,价格为0表示该种供应商没有那一种材料,学校想处理的越简单越好,所以打算选择一个可以提供三种材料的某一家供应商来买,且三种材料的平均价格越低越好。

输入描述 Input Description

第一行:n,表示有n个供应商,n<=60
接下来n行:每行先有一个字符串表示供应商的名字,然后有三个数字分别表示三种不同材料的价格,价格为0表示此家供应商没有那一种材料

输出描述 Output Description

输出一行,为选中的供应商的信息,包括供应商的名字和此家三种材料的价格(如果有多个供应商材料平均价格最低,则选择第一种材料价格最低的供应商)

样例输入 Sample Input

10 IuUjgKA 9 0 10 v 6 0 2 JBhLeCdA 8 9 1 ZPymTsna 7 8 1 DaCpcjBR 8 1 0 K 6 6 1 lh 8 3 4 YNgoOdBU 8 10 4 Lh 10 5 7 WbKuli 3 6 1

样例输出 Sample Output

WbKuli 3 6 1

WA 80:

#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include<bits/stdc++.h>
using namespace std;
struct xzgys{
	string name;
	int z1,z2,z3;
	int zong(){
		return z1+z2+z3;
	}
}a[70];
int main(){
	int n,jz1,jz2,jz3;
	cin>>n;
	string jname;
	int t=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].name>>a[i].z1>>a[i].z2>>a[i].z3;
	}
	int minn;
	for(int i=1;i<=n;i++){
		if(a[i].z1!=0 && a[i].z2!=0 && a[i].z3){
			minn=a[i].zong();
			break;
		}
	}
	for(int i=2;i<=n;i++){
		if(a[i].z1!=0 && a[i].z2!=0 && a[i].z3 && a[i].zong()<minn){
			minn=a[i].zong();
			jname=a[i].name;
			jz1=a[i].z1;
			jz2=a[i].z2;
			jz3=a[i].z3;
		}
	}
	cout<<jname<<" "<<jz1<<" "<<jz2<<" "<<jz3;
	return 0;
}

 

李奕歌在2021-08-14 12:27:07追加了内容

WA 90:

#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include<bits/stdc++.h>
using namespace std;
struct stu{
	string name;
	int x,y,z;
	double pj(){
		return (x+y+z)/3.0;
	}
}a[65];
int n,minn=1000;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].name>>a[i].x>>a[i].y>>a[i].z;
	}
	int p;
	for(int i=1;i<=n;i++){
		if(a[i].pj()<minn&&a[i].x!=0&&a[i].y!=0&&a[i].z!=0){
			minn=a[i].pj();
			p=i;
		}
	}
	cout<<a[p].name<<" "<<a[p].x<<" "<<a[p].y<<" "<<a[p].z;
	return 0;
}

 


0
已采纳
王文博
王文博
缔造者之神
缔造者之神

下次问问题记得直接告诉我题号就可以啦

 

0
李锦昊
李锦昊
中级天翼
中级天翼

结构体

struct stu{
    string name;
    int x,y,z;
    double pj(){
        return (x+y+z)/3.0;
    }
}a[65];

主函数核心

for(int i=1;i<=n;i++){
        if(a[i].pj()<minn&&a[i].x!=0&&a[i].y!=0&&a[i].z!=0){
            minn=a[i].pj();
            p=i;
        }
    }
    cout<<a[p].name<<" "<<a[p].x<<" "<<a[p].y<<" "<<a[p].z;

 

我要回答