3 条题解
-
6
考场代码:
(
写得彳艮氵……,O2 差不多能 AC,许多地方可以优化。。)#include<bits/stdc++.h> using namespace std; //WRITTEN by S.H.Z. at 2023 NOIP exam int n_shz=0; //to save the number of words int l_shz=0; //to save the length of words char dic_shz[3010][3010]={}; //define a dictionary typed char to save words //define a compare fuction, to sort the words from big to small bool cmp1_shz(char a, char b){ return a>b; } //define a compare fuction, to sort the words from small to big bool cmp2_shz(char a, char b){ return a<b; } //define a compare fuction, to compare two words bool cmp3_shz(char a[], char b[]){ for(int i=0; i<l_shz; i++){ //comparing the words' letters one by one if(a[i] > b[i]) return 1; //if the letter of A is bigger, then word A must bigger than word B else if(a[i] < b[i]) return 0; //if the letter of A is smaller, then word A must smaller than word B else ; //if the letter of A is the same as B, then continue to compare until find a letter that is different } return 0; } int main(){ freopen("dict.in", "r", stdin); freopen("dict.out", "w", stdout); //STEP 1: INPUT scanf("%d%d", &n_shz, &l_shz); //inputting each word in range for(int i=0; i<n_shz; i++){ scanf("%s", dic_shz[i]); //sort the word's letters from big to small to deal with the next step of comparing sort(dic_shz[i], dic_shz[i]+l_shz, cmp1_shz); } //STEP 2: COMPARE for(int i=0; i<n_shz; i++){ char tent_shz[3010]={}; //to save the word in tent for(int j=0; j<l_shz; j++) tent_shz[j] = dic_shz[i][j]; //this time, sort the word's letters from small to big sort(tent_shz, tent_shz+l_shz, cmp2_shz); int flag_shz=1; //a flag to record if this word is smaller than the others, also the output result for(int j=0; j<n_shz; j++){ if(i == j) continue; //a word can not compare with itself //if there is a word bigger than this, then print zero if(cmp3_shz(tent_shz, dic_shz[j])){ flag_shz = 0; break; } } //STEP 3: OUTPUT //if there isn't, then print one printf("%d", flag_shz); } fclose(stdin); fclose(stdout); return 0; }
-
3
我这个没参赛的也发个题解叭,思路和@ 2023lishuhang (李书航)的差不多
才怪差点超时,既然这样,那发布格式也遵照一下啦(呃,虽然只补充一个)介绍一个新的
东西——goto定义:
a: //a为任意合法变量名称 { ...... }
调用:
goto a;
优点:很灵活,可代替continue和break,也可代替循环
还是别想了缺点:你多用的话还算清醒就没有缺点
具体用法看下面代码
#include <bits/stdc++.h> using namespace std; int n,m,b[5500][5500],c[5500][5500];//原,从小到大,从大到小 char a[5500][5500]; int main() { freopen("dict.in","r",stdin); freopen("dict.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>a[i][j]; b[i][j]=c[i][j]=a[i][j]-96; } sort(b[i]+1,b[i]+m+1); for(int j=m;j>=1;j--) c[i][m-j+1]=b[i][j]; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { for(int k=1;k<=m;k++) { if(b[i][k]<c[j][k]&&i!=j) goto bb; else if(b[i][k]>c[j][k]&&i!=j) { printf("0"); goto aa; } } bb:{if(j==n)printf("1");} } aa:{} } return 0; }
-
3
谨以此篇题解纪念我那寄了的NOIP T1
这是一道炒鸡简单的题目,就是一个普通的和字符串有关的题目,代码很短,你需要掌握的知识如下:
- 字符串的读入
- STL库中sort()函数的使用,以及自定义排序的使用
- cstring头文件中strcmp或strncmp的使用
(其实上面的东西都可以被代替,具体可见宋昊哲同志的题解)
本题的思路其实就是: 1.对每个字符串中的字母从小到大进行排序(这个操作可以不用数组单独计数) 2.对每个字符串中的字母从大到小排序,再将上面得出的字符串与这些从大到小的字符串比较,看是否能比这些小,是则输出1,否则输出0 下面是代码(记得开O2优化)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m; char ss[3010][3100]; char compare[3010][3010];//从大到小排序 char tmp1[3100]; const bool cmp1(const char &a,const char &b) { return a>b;//从大到小排序 } int main() { freopen("dict.in","r",stdin); freopen("dict.out","w",stdout); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { //getchar();//读取换行符 scanf("%s",ss[i]); strncpy(compare[i],ss[i],m); sort(compare[i],compare[i]+m,cmp1); } for (int i=1;i<=n;i++) { int tmp=1; memset(tmp1,0,sizeof(tmp1)); strncpy(tmp1,ss[i],m); sort(tmp1,tmp1+m);//对自己进行操作,从小到大排序字母 for (int j=1;j<=n;j++) { if (j==i) continue;//遇到自己直接跳过 if (strcmp(tmp1,compare[j])>0) { tmp=0; break; } } printf("%d",tmp); } return 0; }
- 1
信息
- ID
- 2027
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 48
- 已通过
- 10
- 上传者