标签:blog io for sp div 问题 log bs amp
int candy(vector<int> &ratings) { vector<int> priority(ratings); for(int i=0;i<priority.size();i++) ratings[i]=1; //_从右往左比 for(int i=1;i<priority.size();i++) { if(priority[i]>priority[i-1]&&ratings[i]<=ratings[i-1]) ratings[i]=ratings[i-1]+1; //if(priority[i]==priority[i-1]) ratings[i]=ratings[i-1]; //_晕,不需考虑同级情况,要注释掉才对 } //_从左往右比 for(int i=priority.size()-1;i>0;i--) { if(priority[i-1]>priority[i]&&ratings[i-1]<=ratings[i]) ratings[i-1]=ratings[i]+1; //if(priority[i-1]==priority[i]) ratings[i-1]=ratings[i]; } int sum=0; for(int i=0;i<priority.size();i++) sum+=ratings[i]; return sum; }
标签:blog io for sp div 问题 log bs amp
原文地址:http://www.cnblogs.com/shirishiyue/p/4077312.html