Skip to content

Instantly share code, notes, and snippets.

@nishidy
nishidy / sever_select_tcp.cpp
Last active August 29, 2015 14:19
select (Blocking I/O)
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#define CONCURRENT 10
@nishidy
nishidy / server_epoll_tcp.cpp
Last active August 29, 2015 14:19
epoll (Non Blocking I/O)
#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
@nishidy
nishidy / client_tcp.py
Last active August 29, 2015 14:19
client example
import sys
import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect(("127.0.0.1",11111))
s="0"+"1"*5000+"9"
while True:
#print len(s)
#sock.send(s)
@nishidy
nishidy / a.py
Last active August 29, 2015 14:23
Round 1C 2015: Problem A. Brattleship
T=int(raw_input())
t=0
while t<T:
R,C,W=map(lambda x: int(x), raw_input().split())
a=(C/W)*R+(W-1)+(1 if C%W>0 else 0)
t+=1
print "Case #%d: %d"%(t,a)
@nishidy
nishidy / b.py
Last active August 29, 2015 14:23
Round 1C 2015: Problem B. Typewriter Monkey
from math import *
T=int(raw_input())
t=0
while t<T:
K,L,S=map(lambda x:int(x),raw_input().split())
k=raw_input()
l=raw_input()
n=0
@nishidy
nishidy / c_small.py
Created June 29, 2015 15:16
Round 1C 2015: Problem C. Less Money, More Problems
from bisect import bisect_left
def ins_d(n):
global d
if n>=d[-1]:
d+=[n]*C
else:
sep=bisect_left(d,n)
d=d[:sep]+[n]*C+d[sep:]
@nishidy
nishidy / c_large.py
Created June 29, 2015 15:17
Round 1C 2015: Problem C. Less Money, More Problems
T=int(raw_input())
t=0
while t<T:
C,D,V=map(lambda x:int(x),raw_input().split())
d=sorted(map(lambda x:int(x),raw_input().split()))
a=0;n=1;s=0;pn=0
while n<=V:
if n in d:
@nishidy
nishidy / a.py
Created July 9, 2015 08:36
Round 2 2015: Problem A. Pegman (small/large)
def crosscheck(ri,ci,R,C,rect):
for cidx in range(ci+1,C):
if rect[ri][cidx] != '.':
return "COK"
for cidx in range(ci-1,-1,-1):
if rect[ri][cidx] != '.':
return "COK"
for ridx in range(ri+1,R):
@nishidy
nishidy / demo.erl
Last active August 29, 2015 14:26
Demo for process_flag
-module(demo).
-compile(export_all).
start(Bool, M) ->
A = spawn(fun()->a()end),
B = spawn(fun()->b(A,Bool)end),
C = spawn(fun()->c(B,M)end),
sleep(1000),
status(b,B),
status(c,C).
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void show(Mat *img){
cout << "Width " << img->cols << " / Height " << img->rows << endl;
imshow("Image", *img);