寺ç°å¯ 彦
科学者とあたまãæ¸ããã²ã¨ã ããã©ãããã®ååã©ã£ãã§èããäºããããªã¨æã£ãã, æ¨æ¥åå£é年座ã®äººã®è¬æ¼ã§èããã®ã ã£ãã
ããã¦ãã³ãã¨ããåå£é年座ã®å
¬æ¼ãææ¥NHKã§æ¾éããããããã§ããå¬å½¦ã£ã¦ã®ã¯å¯ºç°å¯
彦ã®ãã³ãã¼ã ãããã
http://cgi4.nhk.or.jp/hensei/program/p.cgi?area=001&date=2008-12-12&ch=31&eid=9950
ããããããã ãã観ã¦ã¿ããããªã
ã¨ããã§å°æ´å çãåããããªäºãè¨ã£ã¦ããã®ãæãåºããããã®ã¤ã³ã¿ãã¥ã¼ã¯é¢ç½ãã
ä¸æµã®çè«å®¶ã¯ããèªåã®çè«ã§ã¯ãããã¾ã§ã¯ä½¿ããããã©ãããããå ã¯åãããªããã¨ããé©ç¨éçããã¤ãæèãã¦ãããã¨ãããäºæµã®çè«å®¶ã¨ããã®ã¯ãèªåãååãè¦ããããããã¯ã使ã£ãçè«ã§ä½ã§ããããã¨æã£ã¦ãã¾ããäºæµã®çè«å®¶ã«å°ããããã®ã¯ãæ°ããå®é¨è¨ç»ãåºã¦ããããèªåã®çè«ãããããã¯æçã§ããªãããããããªãã®ã¯ã¤ã¾ããã¨è¨ã£ã¦ã¯ããã¡ããã¨ããã ãã
東京大学理学部2006-2007 - 東京大学 大学院理学系研究科・理学部
(ä¸ç¥)
äºæµã®çè«å®¶ã¨ããã®ã¯ãç©äºãå ¨é¨ç¥ã£ã¦ããã¨æã£ã¦ãããããããã£ã¦å®³ãåã¼ããã¨ãå¤ããã ã
åç §ã¨ãã¤ã³ã¿ã®éã
åç
§ã¨ãã¤ã³ã¿ã®æ©è½é¢ã®éãã¨ããã®ã¯è¯ãç¥ããã¦ãããã¨æãã¾ãã,ã³ã¼ãçæã®éãã«é¢ãã¦ã¯çµæ§ç¥ããªãæ¹ãå¤ãã®ããã¨æã解説ãã¾ãã
è¨äºã大å¤é·ããªã£ã¦ãã¾ãã¾ããã, å人çã«ã¯åç
§ã¯é常ã«é¢ç½ãç©ã ã¨æã£ã¦ãã¾ãã¦ãããä¼ããã°ã¨æãã¾ããããä½ãééããããã°èª°ãæãã¦ä¸ããã
ã¾ã, åç §ã¨ã¯ã¤ã¾ãã¨ã¤ãªã¢ã¹(å¥å)ã ã¨ããã®ã¯è¯ããã¨æãã¾ãã,ãããã©ãå®ç¾ãããã«é¢ãã¦è¦æ ¼ã¯ä¸åè¨åãã¦ããªããã§ãããã©ããããã¯ã³ã³ãã¤ã©ã®èªç±ã§ãã
å ·ä½çã«ã©ãããå®ç¾æ¹æ³ããããã¨ããã¨, unionããã¼ãã¦ã§ã¢åºæã®æ©è½ã®å©ç¨(ç¹æ®ãªã¡ã¢ãªã¨ã)ããããã¾ãã,ç¾å®çã«ã¯
- ãã¤ã³ã¿
- ååç½®æ (åããæãè¨ã㨠#define x y ã¿ãããªãã ã®ç½®æ)
ãã»ã¨ãã©ã ã¨æãã¾ãã
C++ã®åç
§ã¯å代å
¥ä¸å¯, ã¢ãã¬ã¹åå¾ä¸å¯çã®å¶ç´ãããããç°¡åãªè§£æã§å¾è
ã«ã使ããã¨ããã®ããã¤ã³ãã§, Javaãªã©ã®åç
§ã¨ã¯ç°ãªã£ã¦ãã¾ãã
ããã¦, ã³ã³ãã¤ã©ã¯ãã¤ã³ã¿ãªãã¦æ¥µå使ããããªãã®ã§, å¯è½ãªå ´åã¯ç½®æã§åç §ãå¦çãã¾ãã
ã§ã¯, ã©ãããå ´åã«ãã¤ã³ã¿ã使ç¨ãããã¨ããã¨ä»ã®é¢æ°ã®å¼æ°ã¨ãã¦æ¸¡ãå ´åç, ããããããå¾ãªãå ´åã§ããä¾ãã°
void pair_swap(std::pair<int, int> &p) { int t = p.first; p.first = p.second; p.second = t; }
ã¨
void pair_swap(std::pair<int, int> *p) { int t = p->first; p->first = p->second; p->second = t; }
ã¯é常ã¯ã»ã¼åãã¢ã»ã³ããªã«ãªãã¨æãã¾ãã
次ã«ããããã¤ã³ã©ã¤ã³åãããå ´åãèãã¦ã¿ã¾ãã
åç §ã®å ´å
std::pair<int,int> x = std::make_pair(0, 1); pair_swap(x); std::cout << x.first << x.second << std::endl;
ã
std::pair<int,int> x = std::make_pair(0, 1); std::pair<int,int> &p = x; int t = p.first; p.first = p.second; p.second = t; std::cout << x.first << x.second << std::endl;
ã«ãªãã¾ããããã¨,ãã¯ãpããã¤ã³ã¿ã§ããå¿ è¦ããªãã®ã§,ãã ã®ç½®æã§å¦çãã¾ãã
std::pair<int,int> x = std::make_pair(0, 1); int t = x.first; x.first = x.second; x.second = t; std::cout << x.first << x.second << std::endl;
次ã«, å ¨ã¦ã®ã¢ã¯ã»ã¹ãx.firstãx.secondã®å½¢ãªã®ã§, xã«é£ç¶é åãå²ãå½ã¦ãå¿ è¦ããªãäºã解æãã,pairã¯ãã©ãã©ã«å解ããã¾ãã
int x_first = 0; int x_second = 1; int t = x_first; x_first = x_second; x_second = t; std::cout << x_first << x_second << std::endl;
æçµçã«å®æ°ç³ã¿è¾¼ã¿ã§
std::cout << 1 << 0 << std::endl;
ã«ãªãã¾ãããããªæãã§åç §ãå©ç¨ããã¨, ä»ã®ã³ã¼ãå¤æã®å¹æãåä¸ããå ´åãçµæ§ããã¾ãã
ãã¤ã³ã¿ã®å ´å
ã¤ã³ã©ã¤ã³åããã¨
std::pair<int,int> x = std::make_pair(0, 1); std::pair<int,int> *p = &x; int t = p->first; p->first = p->second; p->second = t; std::cout << x.first << x.second << std::endl;
ã¨ãªãã¾ãããã¦, ããã®æé©åã¯å°é£ã§ããpã¯åä»£å ¥ãªã©ãå¯è½ãªã®ã§, ãã ã®ç½®æã§ã¯å¦çã§ãã¾ãããããæé©åããããçºã«ã¯ã¨ã¤ãªã¢ã¹è§£æã¨ããé«åº¦ãªè§£æãå¿ è¦ã«ãªãã¾ãã
g++ã®å ´åã¯, ãã®ç¨åº¦ã®åç´ãªã³ã¼ãã§ããã°-O2ã§ä¸¡è
ã¨ãå
¨ãåãã³ã¼ãã«ãªãã¾ãã, ã³ã³ãã¤ã©ã®è¦å´åº¦åã¯å
¨ç¶éããã§ããã
ã¨ã¤ãªã¢ã¹è§£æã¯å®å
¨ã«è¡ãäºãå°é£ãªã®ã§,åå²ãå
¥ã£ãè¤éãªã³ã¼ãã«ãªãã¨-O2ã§ãå·®ãç¾ãã¦ããã¨æãã¾ãã
ã¾ã¨ãã§ãã, åç §ã¯å¯è½ãªå ´åã¯åãªãç½®æã§å¦çãããã®ã§çæãããã³ã¼ããå¤ãã£ã¦ãã¾ãããã£ã¨é¢ç½ãäºããã¦ããã³ã³ãã¤ã©ãããããããã¾ããã
ããã«æ¸ããã®ã¯åç
§ã®å®ç¾ã®ä¸å½¢æ
ã§ãã£ã¦, å¦çç³»ã«ãã£ã¦ç°ãªãã¨ãããã¨ã«æ³¨æãã¦ããã¾ããå°ãªãã¨ãg++ã§ã¯ä»¥ä¸ã®ãããªæãã«ãªã£ã¦ããããã§ãã[追è¨]ããã¯èª¿ã¹ãªããã¾ãã