连续熬夜两场,确实到了规划自己将来的时候了,衣服到了呢,这次可不能输
A - Game
思路:这个签到题确实有点过于友好了,就是个简单的寻找中位数,确定没什么坑点后果断提交
#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 = 1e3+10;
int a[maxn];
int main()
{
int n;
ios::sync_with_stdio(false);
cin >> n;
for(int i=0;i<n;i++)
{
cin >> a[i];
}
sort(a,a+n);
cout << a[(n+1)/2-1] << endl;
return 0;
}
B - Minesweeper
思路:猛地发现,这题不就是一个扫雷游戏吗,如此小规模的图,直接遍历就ok了,倒是要稍微增加一下码代码速率,美观一下代码格式或许会有好效果
#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 = 110;
char bomb[maxn][maxn];
int xx[8]={-1,0,1,-1,1,-1,0,1};
int yy[8]={-1,-1,-1,0,0,1,1,1};
int check(int x,int y)
{
int num = 0;
for(int i=0;i<8;i++)
{
int nx = x + xx[i];
int ny = y + yy[i];
if(bomb[nx][ny] == '*')
{
num++;
}
}
return num;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
getchar();
for(int j=1;j<=m;j++)
{
scanf("%c",&bomb[i][j]);
}
}
bool win = true;
for(int i=1;win&&i<=n;i++)
{
for(int j=1;win&&j<=m;j++)
{
int num = check(i,j);
if(bomb[i][j] == '.')
{
if(num>0)
{
win = false;
}
}
else if(bomb[i][j] == '*')
{
continue;
}
else
{
if(bomb[i][j] - '0' != num)
{
win = false;
}
}
}
}
if(win)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}
C - Finite or not?
思路:就是判断分子分母约分后,分母的质因子是否有不是基数的质因数
考虑到分解质因数是一个O(sqrt(n))的算法,于是考虑到O(log(n))的辗转相除求最大公约数
这题卡掉了O(log(log(n)))的做法,而需要加个小小优化,以gcd不断更新操作数,使得数据变小,这题大多是思路的问题,清晰的思路成就结果
#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;
typedef long long ll;
int main()
{
//cout << 24%6;
int n;
scanf("%d",&n);
while(n--)
{
ll p,q,b;
scanf("%I64d%I64d%I64d",&p,&q,&b);
ll temp = __gcd(p,q);
q /= temp;
//ll nq = 1LL;
temp = b;
while(temp > 1LL)
{
temp = __gcd(q,temp);
//nq = q;
q /= temp;
}
if(q == 1LL)
{
printf("Finite\n");
}
else
{
printf("Infinite\n");
}
}
return 0;
}
D - XOR-pyramid
这题一开始想的是利用异或的性质找规律,然而无功而返
其实注意到这题n只有1000,于是可以预处理最大值,dp处理一下,说真的,只要思路想到了,这题完全成了最基础的dp问题
#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 = 5e3+10;
typedef long long ll;
ll a[maxn][maxn];
ll re[maxn][maxn];
int main()
{
//cout << (30 ^ 60) << endl;
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%I64d",&a[0][i]);
re[0][i] = a[0][i];
}
for(int i=1;i<n;i++)
{
for(int j=0;j<n-i;j++)
{
a[i][j] = (a[i-1][j] ^ a[i-1][j+1]);
re[i][j] = max(max(re[i-1][j],re[i-1][j+1]),a[i][j]);
//cout << re[i][j] << "*";
}
//cout << endl;
}
/*for(int i=1;i<n;i++)
{
for(int j=0;j<n-i;j++)
{
cout << a[i][j] << "*";
}
cout << endl;
}*/
int q;
scanf("%d",&q);
while(q--)
{
int l,r;
scanf("%d%d",&l,&r);
int len = r-l;
printf("%I64d\n",re[len][l-1]);
}
return 0;
}