#include"7662.h"
// 답지 봄.
void B7662::Solution()
{
char c;
int T, k, n;
std::cin >> T;
while (T--)
{
std::cin >> k;
std::multiset<int> ms;
for (int i = 0; i < k; ++i)
{
std::cin >> c >> n;
if (c == 'I'){
ms.insert(n);
}
else if (c == 'D') {
if (ms.empty()) {
continue;
}
else if (n == 1) {
auto iter = ms.end();
iter--;
ms.erase(iter);
}
else if (n == -1) {
ms.erase(ms.begin());
}
}
}
if (ms.empty()) {
std::cout << "EMPTY" << '\n';
}
else {
auto iter = ms.end();
iter--;
std::cout << *iter << " " << *ms.begin() << '\n';
}
}
}
template<typename T>
여러 자료형에 대해 작동하는 함수나 클래스를 만듦
vector<T>::reserve(size_t n)
최소한 n개의 요소를 저장할 수 있는 메모리를 미리 할당합니다.
실제 요소 개수는 증가하지 않음 (size()는 그대로).
중간에 reallocation 없이 더 빠르게 .push_back()을 할 수 있음.
#include"17298.h"
void B17298::Solution()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int N;
std::cin >> N;
std::stack<int> stk;
std::vector<int> arr(N);
std::vector<int> res(N,-1);
for(int i=0; i<N; ++i)
{
std::cin >> arr[i];
while (!stk.empty() && arr[stk.top()] < arr[i])
{
res[stk.top()] = arr[i];
stk.pop();
}
stk.push(i);
}
for (int r : res)
{
std::cout << r << ' ';
}
}
#include"1005.h"
namespace
{
//std::vector<int> build_time;
//std::vector<int> full_build_time;
//std::vector<std::vector<int>> build_need;
//int Full_Build_Time(int idx)
//{
// if (full_build_time[idx] != -1) { return full_build_time[idx]; }
// int pre_time = 0;
// for (int pre_idx : build_need[idx])
// {
// pre_time = std::max(pre_time, Full_Build_Time(pre_idx));
// }
// full_build_time[idx] = build_time[idx] + pre_time;
// return full_build_time[idx];
//}
}
void B1005::Solution()
{
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
//int T;
//std::cin >> T;
//while (T--)
//{
// int result_time = 0;
// int N, K; // N : 건물 개수, K : 건물 순서 규칙 개수
// std::cin >> N >> K;
//
// build_time = std::vector<int>(N+1);
// for (int i = 1; i <= N; ++i) { std::cin >> build_time[i]; }
// full_build_time = std::vector<int>(N + 1, -1);
// build_need = std::vector<std::vector<int>>(N+1);
// for (int i = 1; i <= K; ++i)
// {
// int pre, idx;
// std::cin >> pre >> idx;
// build_need[idx].push_back(pre);
// }
// int W; // W : 건설할 건물
// std::cin >> W;
// std::cout << Full_Build_Time(W) << '\n';
//}
// 소요되는 시간은 같음. 아래는 정석대로 위상정렬로 푼 거.
int T, N, K, W;
std::cin >> T;
while (T--)
{
std::cin >> N >> K;
std::vector<int> indegree(N + 1,0);
std::vector<std::vector<int>> next_build(N + 1);
std::vector<int> build_time(N + 1,0);
std::vector<int> full_build_time(N + 1,0);
for (int i = 1; i <= N; ++i){std::cin >> build_time[i];}
for (int i = 1; i <= K; ++i) {
int idx, next;
std::cin >> idx >> next;
next_build[idx].push_back(next);
indegree[next]++;
}
std::cin >> W;
std::queue<int> q;
for (int i = 1; i <= N; ++i) {
if (indegree[i] == 0) {
full_build_time[i] = build_time[i];
q.push(i);
}
}
while (!q.empty()) {
int idx = q.front();
q.pop();
for (int next : next_build[idx]) {
int this_time = full_build_time[idx] + build_time[next];
full_build_time[next] = std::max(full_build_time[next], this_time);
if (--indegree[next] == 0) {
q.push(next);
}
}
}
std::cout << full_build_time[W] << '\n';
}
}
서버와 클라 사이 통신 방법 정리
using FishNet.Object;
using FishNet.Object.Synchronizing;
public class Player : NetworkBehaviour
{
readonly SyncVar<int> _health = new SyncVar<int>(100);
public void StepOnLego()
{
if (!IsServerInitialized)
return;
_health. Value -= 10;
}
}
NetworkBehaviour 에 존재해야 한다.using FishNet.Object;
public class Player : NetworkBehaviour
{
[ServerRpc]
void UpdatePlayerName(string newName)
{
print($"Player {OwnerId} has updated their name to {newname}");
}
}
NetworkBehaviour 클래스 내에 있을 필요도 없다.using FishNet;
using UnityEngine;
public class ChatSystem : MonoBehaviour
{
public void SendChatMessage(string text)
{
ChatBroadcast msg = new ChatBroadcast()
{
Message = text,
FontColor = Color.white
};
InstanceFinder.ClientManager.Broadcast(msg);
}
}
Reliable : 순서대로 도착하는 것이 보장됨.
Unreliable : 대역폭은 적게 쓰지만, 순서도 도착도 보장은 안됨.