不知不觉2017就结束了,难忘2017
想想这一年来,可能算是真正属于acm的一年吧,从2016的迷茫,到2017的摸索,寒假的usaco,到5月份的第一篇博客,一年来,校赛,cccc,省赛,codeM,计蒜客,再到暑假的培训,icpc,ccsp
虽不免存在遗憾,但收获满满
当然,还有一路伴随而来的cf,记录下了多少个迟到的睡眠与涨分的喜悦
2017最后一场cf了,用一场实现个人职业生涯新高的cf分来欢送2017,喜迎2018
A. New Year and Counting Cards
思路:这题其实完全是离散数学领域一个命题理解的问题,已知命题:“元音=>偶数”,要求找出错误命题,前真后假即可,即统计元音和奇数个数
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1e5+10;
char s[maxn];
char sc[10] = {'a','e','i','o','u','1','3','5','7','9'};
int main()
{
scanf("%s",s);
int len = strlen(s);
int sum = 0;
for(int i=0;i<len;i++)
{
for(int j=0;j<10;j++)
{
if(s[i] == sc[j])
{
sum++;
}
}
}
printf("%d\n",sum);
return 0;
}
B. New Year and Buggy Bot
思路:.迷宫问题,类似于方向键控制小人移动最终走出迷宫,上下左右对应不同按键,求按键分配方案而已
那么一共4!=24中分案,枚举dfs就好了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 100;
char mm[maxn][maxn];
int sx,sy,ex,ey;
char intr[110];
char dd[4] = {'D','L','U','R'};
int len;
int sum;
int n,m;
void dfs(int k,int x,int y)
{
if(x<0||x>=n||y<0||y>=m)
{
return ;
}
if(mm[x][y] == 'E')
{
sum++;
return;
}
else if(mm[x][y]=='#')
{
return ;
}
if(k==len)
{
return ;
}
if(dd[intr[k]-'0']=='D')
{
dfs(k+1,x+1,y);
}
else if(dd[intr[k]-'0']=='L')
{
dfs(k+1,x,y-1);
}
else if(dd[intr[k]-'0']=='U')
{
dfs(k+1,x-1,y);
}
else if(dd[intr[k]-'0']=='R')
{
dfs(k+1,x,y+1);
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
{
getchar();
for(int j=0;j<m;j++)
{
scanf("%c",&mm[i][j]);
if(mm[i][j] == 'S')
{
sx = i;
sy = j;
}
else if(mm[i][j] == 'E')
{
ex = i;
ey = j;
}
}
}
getchar();
scanf("%s",intr);
//cout << "**" << endl;
len = strlen(intr);
sum = 0;
for(int d=0;d<4;d++)
{
dd[d] = 'D';
for(int l=0;l<4;l++)
{
if(l==d)
{
continue;
}
dd[l] = 'L';
for(int u=0;u<4;u++)
{
if(u==d||u==l)
{
continue;
}
dd[u] = 'U';
for(int r=0;r<4;r++)
{
if(r==d||r==l||r==u)
{
continue;
}
dd[r] = 'R';
dfs(0,sx,sy);
}
}
}
}
printf("%d\n",sum);
}
return 0;
}
C. New Year and Curling
思路:许久未见计算几何的题了,有点模拟的意味,从上往下扔盘子,盘子不会左右移动,问最后盘子最顶端的高度
这题由于x轴和盘子半径r都不大于1e3且为整数,所以可以考虑离散化统计每个横坐标对应的最上方盘子高度,然后对于每个盘子,遍历左右半径范围内高度,寻找到最高点做个模拟即可
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1010;
double h[maxn];
int main()
{
int n,r;
while(scanf("%d%d",&n,&r)!=EOF)
{
for(int i=1;i<=1000;i++)
{
h[i] = -1.0*double(r);
}
while(n--)
{
int pos;
scanf("%d",&pos);
int st = pos-2*r,en = pos+2*r;
if(st<1)
{
st = 1;
}
if(en>1000)
{
en = 1000;
}
double hh = -1.0*double(r);
for(int i=st;i<=en;i++)
{
double newh = h[i] + sqrt(2.0*double(r)*2.0*double(r) - (double(pos)-double(i))*(double(pos)-double(i)));
if(newh > hh)
{
hh = newh;
}
//cout << hh << endl;
}
if(n==0)
{
printf("%f\n",hh);
}
else
{
printf("%f ",hh);
}
h[pos] = hh;
}
}
return 0;
}