标签:test problems ios bool exp pac false http can
【程序结果:用例未完全通过,本博文仅为暂存代码之目的】
/* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/problem/994/B 思路: step0.对骑士进行编号 step1.按照权力值进行顺序排序 step2.分别计算骑士所能杀死的其他骑士及其对应的金币值 step3.按照编号重新恢复原始排序. */ //#include<bits/stdc++.h> #include<iostream> #include<algorithm> using namespace std; typedef struct Knight{ int id; int power; int coins; int expected_coins; }Knight; bool compare_id(Knight a, Knight b){ if(a.id>b.id) return false; else return true; } bool compare_power(Knight a, Knight b){ if(a.power>b.power) return false; else return true; } int main(){ int n,k,id = 0; Knight *persons; scanf("%d %d", &n, &k); persons = (Knight*)malloc(n*sizeof(Knight)); //printf("\n%d %d", k, n); for(int i=0;i<n;i++){ persons[i].id = ++id; scanf("%d", &(persons[i].power)); } for(int i=0;i<n;i++){ scanf("%d", &(persons[i].coins)); } sort(persons, persons+n, compare_power);//顺序排序:<algorithm> for(int i=0;i<n;i++){//分别计算各骑士能够杀死的人和可以获得的金币最大值 persons[i].expected_coins = persons[i].coins; for(int j=1;j<=k;j++){ if(i - j >= 0){ persons[i].expected_coins += persons[i - j].coins; } } } sort(persons, persons+n, compare_id);//依照id恢复原始排序 for(int i=0;i<n;i++){ printf("%d%s", persons[i].expected_coins, ((i + 1) != n ?" ":"\n"));//test //printf("%d %d %d\n", persons[i].power, persons[i].coins, persons[i].expected_coins);//test } return 0; }
Knights of a Polygonal Table(骑士的多角桌)
标签:test problems ios bool exp pac false http can
原文地址:https://www.cnblogs.com/johnnyzen/p/9276125.html