825. Friends Of Appropriate Ages
握手定理
年齡為i的人,和年齡為j的人,最終可配對r(i)Xr(j),同齡人之間可配對數為r(i)X(r(i)-1)
class Solution {
public:
/*
小於等於14,是不可以滴,所以直接從15開始取值
*/
int numFriendRequests(vector<int>& ages) {
vector<int> ren(121,0);
for(auto age:ages) ren[age]++;
int result = 0;
for(int i =15,minage=15,sumage=0;i<121;sumage+=ren[i],result+=ren[i++]*(sumage-1))
while(minage<=0.5*i+7) sumage -=ren[minage++];
return result;
}
};
相關文章
- [LeetCode] 825. Friends Of Appropriate AgesLeetCodeAPP
- D - New Friends
- No appropriate protocolAPPProtocol
- My Friends, Happy XmasAPP
- Good story for dear friends.Go
- set up the appropriate environmentAPP
- man -k : nothing appropriate.APP
- HDU 5119 Happy Matt Friends(DP)APP
- 備份時報no channel allocated for maintenance(of an appropriate type)AINaNAPP
- HDU-3172 Virtual Friends 並查集+map並查集
- ORA-12519 TNS:no appropriate service handler foundAPP
- ORA-12519 TNS no appropriate service handler foundAPP
- ORA-12519, TNS:no appropriate service handler foundAPP
- ORA-12519: TNS:no appropriate service handler foundAPP
- HDU 5119 Happy Matt Friends(簡單二維dp)APP
- Mapper not initialized. Call Initialize with appropriate configuration.APPZed
- 【Case】ORA-12519: TNS:no appropriate service handler foundAPP
- Oracle案例03——RMAN-06091: no channel allocated for maintenance (of an appropriate type)OracleAINaNAPP
- ORA-12519: TNS:no appropriate service handler found 解決APP
- 診斷ORA-12519 TNS:no appropriate service handler foundAPP
- 黑客竊取了超過 2 億個 Zynga“Words with Friends”玩家資料黑客
- Outfit7:Talking Friends系列App下載量超過10億APP
- 2010//11/24 11.24 好友共享美食 Good Food, Good FriendsGo
- ORA-12528: TNS:listener: all appropriate instances are blocking new connectionsAPPBloC
- Ubuntu 更換新 Logo :橙色+矩形 Logo|“Circle of Friends”主題更緊湊更統一UbuntuGo
- 記一次部署在docker環境專案傳送郵件出現No appropriate protocolDockerAPPProtocol
- HDU 5235 Friends (2015 Multi-University Training Contest 2 搜尋+剪枝)AI