程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> LIGHTOJ 1005

LIGHTOJ 1005

編輯:C++入門知識

A - LIGHTOJ 1005 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status

Description

A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizontally from its current position and two rooks attack each other if one is on the path of the other. In the following figure, the dark squares represent the reachable locations for rook R1 from its current position. The figure also shows that the rook R1 and R2 are in attacking positions where R1 and R3 are not. R2 andR3 are also in non-attacking positions.

\

Now, given two numbers n<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPiBhbmQgPHN0cm9uZz5rPC9zdHJvbmc+LCB5b3VyIGpvYiBpcyB0byBkZXRlcm1pbmUgdGhlIG51bWJlciBvZiB3YXlzIG9uZSBjYW4gcHV0IDxzdHJvbmc+azwvc3Ryb25nPiByb29rcyBvbiBhbiA8c3Ryb25nPm4geCBuPC9zdHJvbmc+Y2hlc3Nib2FyZCBzbyB0aGF0IG5vIHR3byBvZiB0aGVtIGFyZSBpbiBhdHRhY2tpbmcgcG9zaXRpb25zLjwvcD4KCgoKPHA+SW5wdXQ8L3A+Cgo8cD5JbnB1dCBzdGFydHMgd2l0aCBhbiBpbnRlZ2VyIDxzdHJvbmc+VCAoodwgMzUwKTwvc3Ryb25nPiwgZGVub3RpbmcgdGhlIG51bWJlciBvZiB0ZXN0IGNhc2VzLjwvcD4KPHA+RWFjaCBjYXNlIGNvbnRhaW5zIHR3byBpbnRlZ2VycyA8c3Ryb25nPm4gKDEgodwgbiCh3CAzMCk8L3N0cm9uZz4gYW5kIDxzdHJvbmc+ayAoMCCh3CBrIKHcIG48c3VwPjI8L3N1cD4pPC9zdHJvbmc+LjwvcD4KCgoKPHA+T3V0cHV0PC9wPgoKPHA+Rm9yIGVhY2ggY2FzZSwgcHJpbnQgdGhlIGNhc2UgbnVtYmVyIGFuZCB0b3RhbCBudW1iZXIgb2Ygd2F5cyBvbmUgY2FuIHB1dCB0aGUgZ2l2ZW4gbnVtYmVyIG9mIHJvb2tzIG9uIGEgY2hlc3Nib2FyZCBvZiB0aGUgZ2l2ZW4gc2l6ZSBzbyB0aGF0IG5vIHR3byBvZiB0aGVtIGFyZSBpbiBhdHRhY2tpbmcgcG9zaXRpb25zLiBZb3UgbWF5IHNhZmVseSBhc3N1bWUgdGhhdCB0aGlzIG51bWJlciB3aWxsIGJlIGxlc3MgdGhhbiA8c3Ryb25nPjEwPHN1cD4xNzwvc3VwPjwvc3Ryb25nPi48L3A+CgoKCjxwPlNhbXBsZSBJbnB1dDwvcD4KCjxwPjg8L3A+CjxwPjEgMTwvcD4KPHA+MiAxPC9wPgo8cD4zIDE8L3A+CjxwPjQgMTwvcD4KPHA+NCAyPC9wPgo8cD40IDM8L3A+CjxwPjQgNDwvcD4KPHA+NCA1PC9wPgoKCgo8cD5TYW1wbGUgT3V0cHV0PC9wPgoKPHA+Q2FzZSAxOiAxPC9wPgo8cD5DYXNlIDI6IDQ8L3A+CjxwPkNhc2UgMzogOTwvcD4KPHA+Q2FzZSA0OiAxNjwvcD4KPHA+Q2FzZSA1OiA3MjwvcD4KPHA+Q2FzZSA2OiA5NjwvcD4KPHA+Q2FzZSA3OiAyNDwvcD4KPHA+Q2FzZSA4OiAwPC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">#include #include #include #define LL long long int zuhe[31][31]; int main() { memset(zuhe,0,sizeof(zuhe)); for(int i=1;i<=30;i++) {zuhe[i][1]=i;zuhe[i][0]=1;} for(int i=2;i<=30;i++) for(int j=1;j<=i;j++) { zuhe[i][j]=zuhe[i-1][j]+zuhe[i-1][j-1]; } int m; freopen("input.txt","r",stdin); scanf("%d",&m); LL ans=0; int N,K,count=1; while(m--) { scanf("%d%d",&N,&K); printf("Case %d: ",count);count++; if(K>N)printf("0\n"); else { if(K==0)printf("1\n"); else { LL n=zuhe[N][K]; ans=n*n; for(int i=1;i<=K;i++) ans*=i; printf("%lld\n",ans); } } } return 0; }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved