\(a\)
int a[N];
void solve(){
int n=read();
for(int i=1;i<=n;i++){
a[i]=read();
}
sort(a+1,a+1+n);
int ans=0;
for(int i=1;i<=min(5,n);i++){
if(a[i]<=300)ans++;
}
puts(ans>=5?"Penta Kill":"Shut Down");
//puts(ans>0?"Yes":"No");
}
\(b\)
想了很久,感觉没有不用最短路算法的写法
我这是使用的 \(floyed\) 算法,用 \(dij\) 或者并查集\(+dfs\)也能写。
\(floyed\) 的本质比较接近暴力枚举,大家可以学习一下。
int d[N][N],n,m;
void floyd(){
for (int k = 1; k <= n; k ++ )
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= n; j ++ )
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
void solve(){
while(cin>>n>>m){
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= n; j ++ )
if (i == j) d[i][j] = 0;
else d[i][j] = INF;
for(int i=1;i<=m;i++){
int x=read(),y=read(),w=read();
d[y][x]=w;
d[x][y]=w;
}
floyd();
int x=read(),y=read();
if(d[x][y]==INF)cout<<"No path\n";
else cout<<d[x][y]<<'\n';
}
//puts(ans>0?"YES":"NO");
//puts(ans>0?"Yes":"No");
}
\(c\)
常规画图题
int fac[20][20];
void init(){
fac[1][1]=1;
for(int i=1;i<=10;i++){
fac[i][1]=1;
for(int j=2;j<=i;j++){
fac[i][j]=fac[i-1][j-1]+fac[i-1][j];
}
}
// for(int i=1;i<=10;i++){
// for(int j=1;j<=i;j++){
// cout<<fac[i][j]<<" ";
// }
// cout<<'\n';
// }
}
void solve(){
int n;
while(cin>>n){
for(int i=n;i>=1;i--){
for(int j=1;j<=(n-i);j++){
cout<<" ";
}
for(int j=1;j<=i;j++){
cout<<fac[i][j]<<" ";
}
cout<<'\n';
}
cout<<'\n';
}
//puts(ans>0?"YES":"NO");
//puts(ans>0?"Yes":"No");
}
\(d\)
这是一份昨晚队友手敲的模拟做法
int n, m;
int vis[N];
void init(){
for (int i = 1; i <= n; i++)
vis[i] = 0;
}
void solve(){
while (cin >> n >> m){
init();
int cnt = 0, now = 0;
for (int i = 1; i < n; i++){
cnt = 0;
while (cnt < m){
now = now % n + 1;
if (vis[now] == 0)
cnt++;
}
vis[now] = 1;
}
for (int i = 1; i <= n; i++)
if (vis[i] == 0){
cout << i << endl;
break;
}
}
}
这是用递推公式写的约瑟夫环问题
void solve(){
int n,k;
while(cin>>n>>k){
int ans=0;
for(int i=2;i<=n;i++){
ans=(ans+k)%i;
}
cout<<ans+1<<'\n';
}
//puts(ans>0?"YES":"NO");
//puts(ans>0?"Yes":"No");
}
\(e\)
感觉没什么意思,找了份早年代码贴一下。
#include <stdio.h>
#include <string.h>
int main(){
int n,s,a[7];
char str[20];
for(int i=0;i<=7;i++){
a[i]=0;
}
scanf("%d",&n);
getchar();
while(n--){
gets(str);
s=0;
for(int i=0;i<strlen(str);i++){
if(str[i]>='0'&&str[i]<='9') s=str[i]-'0'+s*10;
else break;
}
if(s>=1&&s<=25)a[0]++;
else if(s>=26&&s<=55)a[1]++;
else if(s>=56&&s<=69)a[2]++;
else if(s>=70&&s<=103)a[3]++;
else if(s>=104&&s<=125)a[4]++;
else if(s>=200&&s<=230)a[5]++;
else if(s>=231&&s<=250)a[6]++;
else a[7]++;
}
printf("%d %d %d %d %d %d %d %d",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
return 0;
}
\(f\)
类型同上。
#include<stdio.h>
int y[5],b[5],t[5],s[5],m[5],j,k;
char a[100000],ch;
int main() {
int i,n;
gets(a);
char *p=a;
i=0;
while(*p!='\0') {
ch=*p;
if(*p!='.')
y[i]=(ch-48)+y[i]*10;
else i++;
*p++;
}
gets(a);
p=a;
i=0;
while(*p!='\0') {
ch=*p;
if(*p!='.')
b[i]=(ch-48)+b[i]*10;
else i++;
*p++;
}
for(i=0; i<4; i++) {
t[i]=(y[i]&b[i]);
}
scanf("%d",&n);
getchar();
for(k=0; k<n; k++) {
int flag=0;
gets(a);
p=a;
i=0;
for(j=0; j<4; j++) {
s[j]=0;
m[j]=0;
}
while(*p!='\0') {
ch=*p;
if(*p!='.')
s[i]=(ch-48)+s[i]*10;
else {
m[i]=(s[i]&b[i]);
if(m[i]!=t[i]) {
flag=1;
}
i++;
}
p++;
}
if(flag==0)
printf("INNER\n");
else
printf("OUTER\n");
}
}
标签:int,题解,void,学期,++,&&,ans,9.6,now
From: https://www.cnblogs.com/edgrass/p/17680863.html