8.21集训笔记
上午
点击查看代码
#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;
}
string : https://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;
}
#include<bits/stdc++.h>
using namespace std;
const int N=110;
//class String{
// char s[10000];
//};
//C/ C++ xxx.cpp ---- 编译 ----> xxx.obj (目标文件)
// 链接 -----> xxx.exe (可执行文件)
//解释:xxx.py
// xxx.java ---- 编译 ----> xxxx.class
int main(){
// char a[30] ="123.5";
// reverse(a,a+5);
// cout<<a<<endl;
// double b = stod(a); // c++11
// cout<<b<<endl;
// cout<< to_string(b)<<endl;
string s("12345678");
reverse(s.begin(), s.end());
cout<<s<<endl;
return 0;
}
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int main(){
int n;
string s;
cin>>n>>s;
n %= 26; // [0,25]
for(int i=0; i<s.size(); i++){
int t=n;
while(t--){
s[i] ++;
if(s[i] > 'z') s[i]='a';
}
}
cout<<s;
return 0;
}
下午结构体
结构体: https://www.cnblogs.com/hellohebin/p/16265572.html
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e3;
struct T{
string name;
int a,b,c,id;
int sum(){ return a+b+c; }
}stu[N];
bool cmp(T a, T b){
if(a.sum()!=b.sum()) return a.sum() > b.sum();
return a.id < b.id;
}
int main() {
int n; cin>>n;
for(int i=0; i<n; i++){
stu[i].id = i;
cin>>stu[i].name>>stu[i].a>>stu[i].b>>stu[i].c;
}
sort(stu, stu+n, cmp);
int i=0;
cout<<stu[i].name<<" "<<stu[i].a<<" "<<stu[i].b<<" "<<stu[i].c;
return 0;
}
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
struct T{
string name;
int s1,s2,s3;
int sum(){ return s1+s2+s3; }
} a[N];
bool cmp(T a,T b){
return a.name < b.name;
}
bool chk(int x,int y){
return abs(a[x].s1-a[y].s1)<=5
&& abs(a[x].s2-a[y].s2)<=5
&& abs(a[x].s3-a[y].s3)<=5
&& abs(a[x].sum()-a[y].sum()) <=10;
}
int main(){
int n; cin>>n;
for(int i=0; i<n; i++){
cin>>a[i].name>>a[i].s1>>a[i].s2>>a[i].s3;
}
sort(a, a+n, cmp);
// <i, j> j --[i+1, n-1]
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
if(chk(i,j)) cout<<a[i].name <<" "<<a[j].name<<endl;
return 0;
}
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=110;
struct T{
string s;
int y,m,d,id;
}a[N];
int n;
bool cmp(T a,T b){
if(a.y != b.y) return a.y < b.y;
if(a.m != b.m) return a.m < b.m;
if(a.d != b.d) return a.d < b.d;
// if( a.y*365 + a.m*30 + a.d != b.y*365 + b.m*30 + b.d)
// return a.y*365 + a.m*30 + a.d < b.y*365 + b.m*30 + b.d;
return a.id > b.id;
}
int main(){
string s;
int y,m,d;
cin>>n;
for(int i=1; i<=n; i++){
cin>>s>>y>>m>>d;
a[i] = {s,y,m,d,i}; // c++11
}
sort(a+1, a+1+n, cmp);
for(int i=1; i<=n; i++) cout<<a[i].s<<endl;
return 0;
}

浙公网安备 33010602011771号