1106. Lowest Price in Supply Chain

来源:互联网 发布:mac双系统重装os x 编辑:程序博客网 时间:2024/05/17 22:05

一开始犯蠢输出直接p*(1+r/100)*(1+r/100)居然还过了两个测试点拿了15分哈哈,机智地骗分~

依旧乞丐版队列+乞丐版层次遍历。

#include <stdio.h>typedef struct tree {int first;int next;}tree;int main(){tree t[100000];int n, i, child_num, ID, Q[100000], front = 0, rear = 0, x, first = 0, cnt = 1, last = 1,retailer=0;double p, r;scanf("%d %lf %lf", &n, &p, &r);for (i = 0; i < n; i++) {t[i].first = -1;scanf("%d",&child_num);while (child_num--) {scanf("%d", &ID);t[ID].next = t[i].first;t[i].first = ID;}}Q[rear++] = 0;int level = 0,min_level=100001;while (front != rear) {x = Q[front++];first++;if (t[x].first == -1) {min_level = level;retailer++;}for (i = t[x].first; i != -1; i = t[i].next) {Q[rear++] = i;cnt++;}if (first == last) {level++;last = cnt;if (min_level < level)break;}}for (i = 0; i < min_level; i++)p *= (1 + r / 100);printf("%.4lf %d",p,retailer);return 0;}

0 0
原创粉丝点击