优秀码风参考
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n,m,k,x,y,o,p,ans=0;
int dx1[13]={2,0,-2,0,1,1,1,0,0,0,-1,-1,-1},
dy1[13]={0,2,0,-2,0,1,-1,1,0,-1,0,1,-1};
int dx2[25]={-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2},
dy2[25]={-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2};
int main()
{
cin>>n>>m>>k;
int a[n+5][n+5];
memset(a,0,sizeof(a));
for(int i=1;i<=m;i++)
{
cin>>x>>y;
for(int j=0;j<13;j++)
a[x+dx1[j]][y+dy1[j]]=1;
}
for(int i=1;i<=k;i++)
{
cin>>o>>p;
for(int j=0;j<25;j++)
a[o+dx2[j]][p+dy2[j]]=1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j]==0)
ans++;
cout<<ans;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n;
char c,ch;
int a,b,q;
int main() {
cin>>n;
while(n--){
cin>>c;
a=0,b=0;
if(isdigit(c)){
a+=c-'0';
c=getchar();
while(c!=' '){
a=a*10+c-'0';
c=getchar();
}
cin>>b;
}
else {ch=c,cin>>a>>b;}
if(ch=='a')cout<<a<<"+"<<b<<"="<<a+b<<endl,q=a+b;
if(ch=='b')cout<<a<<"-"<<b<<"="<<a-b<<endl,q=a-b;
if(ch=='c')cout<<a<<"*"<<b<<"="<<a*b<<endl,q=a*b;
int len=0;
if(a==0)len++;
else while(a)a/=10,len++;
if(b==0)len++;
else while(b)b/=10,len++;
if(q<0)len++,q=-q;
if(q==0)len++;
else while(q)q/=10,len++;
cout<<len+2<<endl;
}
return 0;
}
#结构体的魅力
#include <bits/stdc++.h>
using namespace std;
const int maxn=12;
int n;
struct Matrix
{
int a[maxn][maxn];
void in(){for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf(" %c",a[i]+j);}
Matrix rotate()
{
Matrix ans;
for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans.a[i][j]=a[n-j-1][i];
return ans;
}
Matrix reflex()
{
Matrix ans;
for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans.a[i][j]=a[i][n-j-1];
return ans;
}
bool operator==(Matrix b)
{
for(int i=0;i<n;i++)for(int j=0;j<n;j++)
if(a[i][j]!=b.a[i][j])return false;
return true;
}
}from,to,mid;
int main()
{
scanf("%d",&n);
from.in();to.in();
mid=from;
for(int i=1;i<=3;i++)
{
mid=mid.rotate();
if(mid==to){printf("%d\n",i);return 0;}
}
mid=from.reflex();
if(mid==to){printf("4\n");return 0;}
for(int i=1;i<=3;i++)
{
mid=mid.rotate();
if(mid==to){printf("5\n");return 0;}
}
if(from==to){printf("6\n");return 0;}
printf("7\n");
return 0;
}
调度模拟的神!
#include<bits/stdc++.h>
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
int n,m,ans;
int whe[25][25],tim[25][25],num[405],calc[405],last[25];
bool vis[25][10005];
int main()
{
int i,j;
scanf("%d%d",&m,&n);
fo(i,1,n*m) scanf("%d",&num[i]);
fo(i,1,n) fo(j,1,m) scanf("%d",&whe[i][j]);
fo(i,1,n) fo(j,1,m) scanf("%d",&tim[i][j]);
fo(i,1,n*m)
{
calc[num[i]]++;
int p1=num[i],p2=calc[num[i]],w=whe[p1][p2],t=tim[p1][p2],res=0;
fo(j,last[p1]+1,10000)
{
if(vis[w][j]) res=0;
else res++;
if(res==t) break;
}
int tmp=j;
fo(j,tmp-t+1,tmp) vis[w][j]=1;
last[p1]=tmp;
ans=max(ans,last[p1]);
}
printf("%d\n",ans);
return 0;
}
#字符串展开与三目运算符的神
#include<bits/stdc++.h>
using namespace std;
using namespace std;
int p1,p2,p3;
string a;
void Print(char x,char y)
{
if(x>=y||(!((x>='0'&&x<='9'&&y>='0'&&y<='9')||(x>='a'&&x<='z'&&y>='a'&&y<='z')))){cout<<'-';return;}
for(int i=(p3==1?x+1:y-1);i>x&&i<y;i+=(p3==1?1:-1))
{
for(int j=1;j<=p2;j++)
{
if(p1==3)cout<<'*';
else if(i<'a'||p1==1)cout<<char(i);
else cout<<char(i-32);
}
}
}
int main()
{
cin>>p1>>p2>>p3>>a;
for(int i=0;i<a.size();i++)
{
if(a[i]=='-'&&i!=0)
Print(a[i-1],a[i+1]);
else cout<<a[i];
}
return 0;
}
#神!边界+特征值
#include<bits/stdc++.h>
using namespace std;
char m[12][12];
int f[3],c[3],ans,tdz;
bool zt[160005];
bool xy(){
if(f[1]==c[1] && f[2]==c[2]) return 0;
else return 1;
}
void move(int x,int y,int mi,int h){
if (mi==0){
if (m[x-1][y]=='*') if (h==0) f[0]=1; else c[0]=1;
else if (h==0) f[1]--; else c[1]--;
}else if (mi==1){
if (m[x][y+1]=='*') if (h==0) f[0]=2; else c[0]=2;
else if (h==0) f[2]++; else c[2]++;
}else if (mi==2){
if (m[x+1][y]=='*') if (h==0) f[0]=3; else c[0]=3;
else if (h==0) f[1]++; else c[1]++;
}else{
if (m[x][y-1]=='*') if (h==0) f[0]=0; else c[0]=0;
else if (h==0) f[2]--; else c[2]--;
}
}
int main()
{
for (int i=0;i<=11;i++) m[i][0]='*',m[i][11]='*';
for (int i=1;i<=11;i++) m[0][i]='*',m[11][i]='*';
for (int i=1;i<=10;i++){
for (int j=1;j<=10;j++){
cin>>m[i][j];
if (m[i][j]=='F') f[1]=i,f[2]=j;
if (m[i][j]=='C') c[1]=i,c[2]=j;
}
}
while(xy()){
tdz = f[1]+f[2]*10+c[1]*100+c[2]*1000+f[0]*10000+c[0]*40000;
if(zt[tdz]){
cout<<0<<endl;
return 0;
}
zt[tdz]=1;
move(f[1],f[2],f[0],0);
move(c[1],c[2],c[0],1);
ans++;
}
cout<<ans<<endl;
return 0;
}
#头疼的旋转
#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int a,b,r,o,g[510][510],f[510][510];
int main ()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
g[i][j]=++x;
}
}
for(int i=1;i<=m;i++){
cin>>a>>b>>r>>o;
if(o==0){
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
f[a-b+j][a+b-i] = g[i][j];
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
g[i][j]=f[i][j];
}else{
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
f[a+b-j][b-a+i] = g[i][j];
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
g[i][j]=f[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<g[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000+10;
struct Stu{
string name;
int c,m,e;
}a[MAXN];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].c>>a[i].m>>a[i].e;
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int ans=abs(a[i].c-a[j].c);
int ans1=abs(a[i].m-a[j].m);
int ans2=abs(a[i].e-a[j].e);
int ans3=abs(a[i].e+a[i].c+a[i].m-a[j].c -a[j].m-a[j].e);
if(ans<=5&&ans1<=5&&ans2<=5&&ans3<=10){
if(a[i].name>a[j].name)
cout<<a[j].name<<" "<<a[i].name<<"\n";
else cout<<a[i].name<<" "<<a[j].name<<"\n";
}
}
}
return 0;
}
另类杨辉三角
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
int yanghui[2][maxn],n,p;
int main()
{
scanf("%d",&p);
n=1<<p;
memset(yanghui,0,sizeof(yanghui));
for(int i=1;i<=n;i++)
{
for(int j=n-i;j>=1;j--)
printf("0 ");
int k=i%2;
yanghui[k][i]=1;
for(int j=1;j<i;j++)
yanghui[k][j]=yanghui[!k][j]+yanghui[!k][j-1];
for(int j=1;j<=i;j++)
if(yanghui[k][j]%2)
printf("1 ");
else
printf("0 ");
printf("\n");
}
return 0;
}
#神の打表
#include <bits/stdc++.h>
using namespace std;
map<char, int> m;
char c;
int main()
{
while (cin >> c)
if (c >= 'A' && c <= 'Z')
m[c]++;
int Max = -1;
for (auto i : m)
if (i.second > Max)
Max = i.second;
for (int i = 0; i < Max; i++)
{
for (int j = 0; j < 26; j++)
if (i >= Max - m[j + 'A'])
cout << "* ";
else
cout << " ";
cout << endl;
}
for (auto i : m)
cout << i.first << " ";
return 0;
}