8.21集训笔记

发布时间 2023-08-21 14:24:33作者: HelloHeBin

上午

点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=110;
bool a[N][N];
int n,m,k,x,y;
int dx[] = {-1,-1,1,1};
int dy[] = {-1,1,-1,1};
bool in(int x,int y){
    return (x>=1 && x<=n &&y >=1 && y<=n);
}
int main(){
    cin>>n>>m>>k;
    while(m--){
        cin>>x>>y;
        for(int i=y-2; i<=y+2; i++)  if(i>=1 && i<=n) a[x][i] = 1;
        for(int i=x-2; i<=x+2; i++)  if(i>=1 && i<=n) a[i][y] = 1;
        for(int i=0; i<4; i++){
            int tx= x+dx[i], ty=y+dy[i];
            if(in(tx,ty)) a[tx][ty] = 1;
        }
    }
    while(k--){
        cin>>x>>y;
        for(int i=x-2; i<=x+2; i++) 
            for(int j=y-2; j<=y+2; j++) if(in(i,j)) a[i][j] = 1;
    }
    int ans=0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++) if(!a[i][j]) ans++;
    cout<<ans;
    return 0;
}
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=1030;
bool st[N][N];
void dfs(int x1,int y1,int x2,int y2){
    if(x1>=x2) return;
    int px = (x1+x2)/2, py = (y1+y2)/2;
    for(int i=x1; i<=px; i++)
        for(int j=y1; j<=py; j++) st[i][j]=1;
    dfs(x1, py+1, px,y2);
    dfs(px+1, y1, x2, py);
    dfs(px+1, py+1, x2,y2);
}
int main(){
    int n; cin>>n;
    n = (1<<n); //n = pow(2,n);
    dfs(1,1, n,n);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            cout<<!st[i][j]<<" ";
        }cout<<endl;
    }
    return 0;
}

stringhttps://www.cnblogs.com/hellohebin/p/16218020.html
C/C++ API: https://www.shouce.ren/api/c/index.htm#

#include<bits/stdc++.h>
using namespace std;
const int N=10;
char s[N];
char a[10], b[10] ="abc";
//char   1Byte = 8bit [-2^7, 2^7-1]

//int len(char* arr){
int len(char arr[]){
    int i=0;
    for(;  arr[i]!='\0'; i++);
    return i;
} 
void t1(){
    int a,b; char c;
    cin>>a;
    while(cin>>c>>b){ // 连续读入,win:回车 ctrl+z 回车 ,结束输入
        a += b;
    }
    cout<<a;
}
int main(){
//    gets(s); // 因为溢出问题,在 C11 = C语言2011年版本 抛弃
    scanf("%s", s);         // cin>>s; 
    printf("%d\n", len(s));

    fgets(s, sizeof(s), stdin);//  读入一行,会读入空格,回车符 
    printf("%s\n", s);         // \0 
    puts(s);                 // 自带换行 

    int n = strlen(s);         // 取长度
    int f = strcmp(a,b);     // return a-b;
    strcpy(b, a);             // copy a to b

//    string s;
//     cin>>s;
//    getline(cin, s);
//      cout<<s;

//    string s;
//    while(cin>>s) cout<<s<<" ";

    char a='9';
    cout<<isdigit(a)<<endl; // 判断是不是数字 
    cout<<isalpha(a)<<endl; // 判断是不是字母 
    return 0;
}

下午