A. 学姐的数码管
将每个数字的七段管压入一个数字.
从北美Regional学到的方法: 使用正则表达式, 可以大幅缩短代码长度.
特别注意输出格式.
/*
USER_ID: test#weak_chicken
PROBLEM: 429
SUBMISSION_TIME: 2014-07-19 11:16:12
*/
#include <cstdio>
#include <cstring>
#include <cctype>
#define pw printf(w?"#":" ")
#define ph printf(h?"#":" ")
#define pb printf(g?"#":" ")
using namespace std;
int main()
{
int i, p, q, j, w, h, g, t, n, dig[10], cp[5][2]={3,5,2,4,26,44,16,32,80,96};
bool st=false;
char s[10], num[11]="w$]m.k{%o";
while(~scanf("%d%s",&n,s)){
int len=strlen(s), top=0, dot=-1;
if(st) puts("");
else st=true;
for(i=0; i<len; i++)
if(isdigit(s[i])) dig[top++]=num[s[i]-'0'];
else dot=top;
for(i=0, p=q=n-2; i<5; i++){
for(j=0; j<top; j++){
t=dig[j]; w=t&cp[i][0], h=t&cp[i][1];
if(j) printf(j==dot?(i==4?" # ":" "):" ");
g=!(i&1)&&t&(1<<(i*3/2));
pw; for(int k=1; k<n-1; k++) pb; ph;
}
if(i==1&&p) i--,p--;
if(i==3&&q) i--,q--;
puts("");
}
}
return 0;
}
B. 学姐的旋转图像
模拟C. 字符串
map直接暴力, 配合 ios::sync_with_stdio ,10行可破
D. 田田的账号
可以直接dp公式证明出答案为4的n-1次幂
快速幂解决.
/*
USER_ID: test#weak_chicken
PROBLEM: 428
SUBMISSION_TIME: 2014-07-18 13:52:45
*/
#include<iostream>
using namespace std;
const long long MOD = 1000000007;
int main()
{
int T; cin>>T;
while(T--){
long long n;
cin>>n;
n--;
long long ans = 1,base=4;
while(n){
if(n&1) ans = (ans * base) % MOD;
base = (base * base) % MOD;
n >>= 1;
}
cout<<ans<<endl;
}
}
E. 学姐的数列
可设三维线段dp
暴力合并相邻项求得最大值
初始化时为1, 表明至少1层