第001话 宝可梦,就决定是你了!
等差数列求和公式
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
long long n;
cin >> n;
cout << n*n;
return 0;
}
第002话 宝可梦中心大对决!
如果两数互质连一条边,找一个点尽量多的子图,点两两间都有边。
就是最大团,可以用Bron–Kerbosch算法
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
/*
int n,a[100],g[30][30];
int tp,s[100],ans;
int dfs(int st) {
for (int i = st; i <= n; i++) {
bool ok = 1;
for (int j = 1; j <= tp; j++)
if (g[s[j]][i] != 1) {
ok = 0;
break;
}
if (ok) {
s[++tp] = i;
if (tp > ans) ans = tp;
dfs(i+1);
}
}
}
*/
int gcd(int a,int b) {
return b==0 ? a : gcd(b,a%b);
}
#define N 1010
bool flag[N], a[N][N];
int ans, cnt[N], group[N], n, vis[N];
bool dfs( int u, int pos ){
int i, j;
for( i = u+1; i <= n; i++){
if( cnt[i]+pos <= ans ) return 0;
if( a[u][i] ){
// 与目前团中元素比较,取 Non-N(i)
for( j = 0; j < pos; j++ ) if( !a[i][ vis[j] ] ) break;
if( j == pos ){ // 若为空,则皆与 i 相邻,则此时将i加入到 最大团中
vis[pos] = i;
if( dfs( i, pos+1 ) ) return 1;
}
}
}
if( pos > ans ){
for( i = 0; i < pos; i++ )
group[i] = vis[i]; // 最大团 元素
ans = pos;
return 1;
}
return 0;
}
void maxclique()
{
for (int i = 0; i <= n; i++) vis[i] = cnt[i] = group[i] = flag[i] = 0;
ans=-1;
for(int i=n;i>0;i--)
{
vis[0]=i;
dfs(i,1);
cnt[i]=ans;
}
}
void work() {
cin >> n;
int s[100];
for (int i = 1; i <= n; i++) cin >> s[i];
//sort(a+1,a+n+1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
a[i][j] = (gcd(s[i],s[j])==1);
// cout<<i<<" "<<j<<" "<<a[i][j]<<"\n";
}
maxclique();
printf("%d\n",ans);
}
int main() {
int T;
cin >> T;
while(T--) work();
return 0;
}
第003话 收服宝可梦吧!
送分
有不一样肯定第一个串放弃一位
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char s1[2100000],s2[2100000];
void work() {
scanf("%s%s",s1,s2);
int l1 = strlen(s1),l2 = strlen(s2);
if (l1 != l2+2) {
puts("0");
} else {
int i = 0,j = 0,t = 0;
while (i <= l1 && j <= l2) {
if (s1[i] == s2[j]) {
i++;j++;
} else {
t++;i++;
}
}
// cout<<t<<" "<<l1<<" "<<i<<" "<<j<<"\n";
if (t+l1+1-i == 2) puts("1");
else puts("0");
}
}
int main() {
int T;
cin >> T;
while(T--) work();
return 0;
}
第004话 武士少年的挑战!
送分
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[100];
int main() {
for (int i = 1; i <= 18; i++) {
int x;
cin >> x;
a[x]++;
}
int ans = 18;
for (int i = 1; i <= 13; i++)
if (a[i]==2 || a[i]==3) ans -= 2;
else if(a[i] == 4) ans -= 4;
printf("%d",ans);
return 0;
}
第005话 尼比市的决斗!
恶心模拟
良心在样例把所以情况都告诉你了。
一种方位(UDLR)对应3个情况(见样例)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char a[100][100];
int x,y;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] == 'S') {
x = i; y = j;
}
}
char c = 'D';
cout << c;int cnt = 0;
bool fd = a[x][y]=='T';
while (!fd) {
if (c=='D') {
if (a[x][y+1]!='#'&&a[x+1][y+1]!='#') {
if(a[x][y+1]=='T') break;
x = x+1;
y = y+1;
c = 'L';
} else if (a[x][y+1]=='#') {
c = 'R';
} else if (a[x][y+1] != '#') {
y = y+1;
}
} else if (c == 'U') {
if (a[x][y-1]!='#' && a[x-1][y-1] != '#') {
if(a[x][y-1]=='T') break;
x = x-1;
y = y-1;
c = 'R';
}
else if (a[x][y-1] == '#') {
c = 'L';
} else if (a[x][y-1] != '#') {
y = y-1;
}
} else if (c == 'R') {
if (a[x-1][y]!='#' && a[x-1][y+1] != '#') {
if(a[x-1][y] == 'T') break;
x = x-1;
y = y+1;
c = 'D';
}
else if (a[x-1][y] == '#') {
c = 'U';
} else if (a[x-1][y] != '#') {
x = x-1;
}
} else if (c == 'L') {
if (a[x+1][y]!='#' && a[x+1][y-1] != '#') {
if(a[x+1][y] == 'T') break;
x = x+1;
y = y-1;
c = 'U';
}
else if (a[x+1][y] == '#') {
c = 'D';
} else if (a[x+1][y] != '#') {
x = x+1;
}
}
fd |= a[x][y] == 'T';
cout << c;// << x << y<<"\n";
// cnt++;if(cnt == 20) return 0;
}
return 0;
}
第006话 皮皮和月亮石!
ok[i][j]记一下以(i,j)为左上角可不可以
删一个点最多影响附近4个,ok数组可以判重。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int ok[1003][1003];
int main() {
int n,m,q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
ok[i][j] = 1;
int sum = (n-1)*(m-1);
for (int i = 1; i <= q; i++) {
int x,y;
cin >> x >> y;
int tp = ok[x][y]+ok[x][y-1]+ok[x-1][y]+ok[x-1][y-1];
ok[x][y] = ok[x][y-1] = ok[x-1][y] = ok[x-1][y-1] = 0;
printf("%d\n",sum=sum-tp);
}
return 0;
}
第007话 华篮市的水中花!
大模拟,比赛时没做完,留坑。
坑
第008话 通向宝可梦擂台之路!
看样例图
在左波只能降低,如果平或增加,只能落地跳到下一个右波
在右波只能增加,如果平或降低,只能通过最高点到左波
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[210000];
int x,y;
int main() {
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
bool L = 1;
int ans = 0;
for (int i = 2; i <= n; i++) {
if (L) {
if (a[i]>=a[i-1]) {
ans ++;
L = 0;
}
} else {
if (a[i] <= a[i-1]) L = 1;
}
}
printf("%d",ans);
return 0;
}