1.AcWing 1351. 密码锁
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
string s,t;
int n;
int find(int v1,int v2){
int res = 0,book[110]={0};
book[v1]++,book[v2]++;
for (int i = 1; i < 3; ++ i){
if((v1 + i) % n == 0)
book[n]++;
else
book[(v1 + i) % n]++;
if((v1 - i + n) % n == 0)
book[n]++;
else
book[(v1 - i + n) % n]++;
if((v2 + i) % n == 0)
book[n]++;
else
book[(v2 + i) % n] ++;
if((v2 - i + n) % n == 0)
book[n]++;
else
book[(v2 - i + n) % n]++;
}
for(int i=1;i<=n;i++)
if(book[i] == 2)
res++;
return res;
}
int main(){
int sum = 0;
scanf("%d",&n);
int a[5],b[5];
scanf("%d %d %d",&a[1],&a[2],&a[3]);
scanf("%d %d %d",&b[1],&b[2],&b[3]);
if(n > 5){
sum = 250;
int mm = 1;
for(int i=1;i<=3;i++)
mm *= find(a[i],b[i]);
sum -= mm;
}
else
sum = n*n*n;
printf("%d\n",sum);
return 0;
}
2.AcWing 1944. 记录保存
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
bool cmp(string x,string y){
return x < y;
}
unordered_map<string,int> m;
int main(){
int n;
cin >> n;
for(int i=1;i<=n;i++){
string s;
string t[5];
for(int j=1;j<=3;j++)
cin>>t[j];
sort(t+1,t+4,cmp);
for(int j=1;j<=3;j++)
s+=t[j],s+="*";
m[s]++;
}
int maxx = 0;
for(auto &t : m){
if(t.second > maxx)
maxx = t.second;
}
cout<<maxx;
return 0;
}
3.AcWing 1353. 滑雪场设计
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int n;
int h[N];
int main(){
cin >> n;
for(int i = 0;i<n;i++) cin>>h[i];
int res = 1e8;
for(int i = 0;i + 17 <= 100 ;i++){
int cost = 0,l = i,r = i+ 17;
for(int j=0;j<n;j++){
if(h[j]<l)
cost += (l-h[j])*(l-h[j]);
else if(h[j] > r)
cost += (h[j]-r)*(h[j]-r);
}
res=min(res,cost);
}
cout<<res<<endl;
return 0;
}
4.AcWing 1929. 镜子田地
AC代码:
//官方代码niu
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int n, m;
char g[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dfs(int x, int y, int d){
if (x < 0 || x >= n || y < 0 || y >= m)
return 0;
if (g[x][y] == '/')
d ^= 1;
else
d ^= 3;
return dfs(x + dx[d], y + dy[d], d) + 1;
}
int main(){
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i ++ )
scanf("%s", g[i]);
int res = 0;
for (int i = 0; i < n; i ++ ){
res = max(res, dfs(i, 0, 1));
res = max(res, dfs(i, m - 1, 3));
}
for (int i = 0; i < m; i ++ ){
res = max(res, dfs(0, i, 2));
res = max(res, dfs(n - 1, i, 0));
}
cout << res << endl;
return 0;
}