#include "bits/stdc++.h"
using namespace std;
main(){
int kase;cin>>kase;
while(kase--){
int n;cin>>n;
vector<int> vec(n);
for(int &i:vec) cin>>i;
sort(vec.begin(),vec.end());
int mid = vec[vec.size()/2-1+vec.size()%2],sum=0;
for(int i:vec)
sum+= abs(mid-i);
cout<<sum<<endl;
}
}
#include "bits/stdc++.h"
using namespace std;
int m,n;
bool cmp(int a,int b){
if(a%m!=b%m){
return (a%m)<(b%m);
}
else{
if((a%2)&&!(b%2))
return 1;
if(!(a%2)&&(b%2))
return 0;
if((a%2)&&(b%2))
return a>b;
if(!(a%2)&&!(b%2))
return a<b;
}
}
main(){
while(cin>>n>>m){
cout<<n<<' '<<m<<endl;
if(!n||!m) break;
vector<int> vec(n);
for(int& i:vec)
cin>>i;
sort(vec.begin(),vec.end(),cmp);
for(int i:vec)
cout<<i<<endl;
}
}
import pygame import random im pygame.init() 定義遊戲視窗大小 WIDTH = 600 HEIGHT = 200 screen = pygame.display.set_mode((WIDTH, HEIGHT))
Jun 17, 2025Pygame 教學 (一) 共筆:https://hackmd.io/LuheTD_SQwWYa2wMwiv65g 匿名提問 前情提要 我們今天要來做打磚塊! 在這之前 我們來把遊戲的流程釐清一下
Dec 2, 2021並查集 目標 判斷連通 , 找兩個點有沒有在同個集合裡面 ( 有同個father,血緣關係 ) 實作 準備一個 陣列 存根節點 並把根結點 設為自己 製作兩個 funtion
Dec 12, 2020Graph Searching [ ] BFS [ ] DFS Shortest Path [x] Dijkstra [ ] Floyd-Warshall
Oct 31, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up