codeforces 183A Headquarters
上次比赛比较有趣的一道题目, 就做了这一题...
初看不好想,经过分析,就会发现其实就是让你求一个矩阵面积。
比如说 我定义 左上 右下就是 来增长 边, 定义 左下右上 来增长 宽, 上左下右 来增长 宽和边。
ans = l * h
View Code
1 #include <iostream> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include <algorithm> 6 using namespace std; 7 typedef __int64 LL; 8 #define inf 10000000 9 #define N 20010 10 int main (){ 11 LL n, num[5]; 12 char str[5]; 13 while (scanf ("%I64d", &n) != EOF) { 14 memset(num, 0,sizeof(num)); 15 for (LL i = 0; i < n; ++i) { 16 scanf ("%s", str); 17 if(strcmp (str, "UR")==0) num[1] ++; 18 if(strcmp (str, "UL")==0) num[2] ++; 19 if(strcmp (str, "DR")==0) num[4] ++; 20 if(strcmp (str, "DL")==0) num[3] ++; 21 if(strcmp (str, "ULDR")==0) num[0] ++; 22 } 23 LL len1, len2, ans; 24 len1 = 1 + num[1] + num[3] +num[0]; 25 len2 = 1 + num[2] + num[4] +num[0]; 26 ans = len1 *len2; 27 printf("%I64d\n", ans); 28 29 } 30 return 0; 31 }