河南农业大学热身赛标程 A.宅宅的排位赛 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include <stdio.h> #include <bits/stdc++.h> using namespace std ;typedef long long ll;const int maxn = 1e3 + 10 ;const int mod = 1e9 + 7 ;int main () { int t; scanf ("%d" , &t); while (t--){ int a, suma = 0 , sumb = 0 ; for (int i = 0 ; i <= 13 ; i++){ scanf ("%d" , &a); suma += a; } for (int i = 0 ; i <= 13 ; i++){ scanf ("%d" , &a); sumb += a; } printf ("%d\n" , suma - sumb); } return 0 ; }
B.冒泡排序 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <stdio.h> #include <bits/stdc++.h> using namespace std ;int a[120 ];int main () { int t; scanf ("%d" , &t); while (t--){ int n, min_ = 9999 ,id=0 ; scanf ("%d" , &n); for (int i = 0 ; i < n; i++)scanf ("%d" , &a[i]); for (int i = 0 ; i < n; i++){ min_ =a[i]; id = i; for (int j = i; j < n; j++){ if (a[j] <= min_)min_ = a[j], id = j; } swap(a[i], a[id]); } for (int i = 0 ; i < n; i++)printf ("%d\n" , a[i]); } return 0 ; }
C.小刘数字母 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include <stdio.h> #include <bits/stdc++.h> //万能头文件 using namespace std ;char s[10050 ];int main () { int t; char ch; scanf ("%d" ,&t); while (t--){ scanf ("%s" ,s); getchar(); scanf ("%c" ,&ch); int cnt=0 ; int len=strlen (s); for (int i=0 ;i<len;i++){ if (s[i]==ch)cnt++; } printf ("%d\n" ,cnt); } return 0 ; }
D.HH的LCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <stdio.h> #include <bits/stdc++.h> using namespace std ;int main () { int t; scanf ("%d" ,&t); while (t--){ int a,b; scanf ("%d%d" ,&a,&b); printf ("%d\n" ,a*b/__gcd(a,b)); } return 0 ; }
E.斐波那契数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include <stdio.h> #include <bits/stdc++.h> using namespace std ;typedef long long ll;const int maxn = 1e3 + 10 ;const int mod = 1e9 + 7 ;int Fib[maxn];int main () { int cnt = 1 ; Fib[0 ] = 0 ; Fib[1 ] = 1 ; for (int i = 2 ; Fib[i - 1 ] <= 100000 ; i++, cnt++){ Fib[i] = Fib[i - 1 ] + Fib[i - 2 ]; } int t; scanf ("%d" , &t); while (t--){ int n, ans = 0 ; scanf ("%d" , &n); for (int i = 26 ; i >= 1 ; i--){ if (n >= Fib[i])n -= Fib[i], ans++; } printf ("%d\n" , ans); } return 0 ; }
F.辉辉学长爱喝水 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include <stdio.h> #include <bits/stdc++.h> using namespace std ;typedef long long ll;const int maxn = 1e3 + 10 ;const int mod = 1e9 + 7 ;int main () { double n, m; scanf ("%lf%lf" , &n, &m); int a = ceil (n / (m * 2 )); if (n == 0 )printf ("0\n" ); else if (m == 0 )printf ("No answer!\n" ); else if (n-a*m<=0 ){ printf ("1\n" ); } else printf ("%d\n" , a + 1 ); return 0 ; }
G.打麻将 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include <stdio.h> #include <bits/stdc++.h> using namespace std ;bool ok=0 ; bool vis[20 ]; char a[20 ];int d[20 ][5 ];int ttt[11 ];void dfs (int cur,char *str,int cnt) { if (cur>12 )return ; if (cur==12 &&cnt==4 ){ int a=0 ,b=0 ; for (int i=1 ;i<=14 ;i++)if (!vis[i]){vis[i]=true ,a=i;break ;} for (int i=1 ;i<=14 ;i++)if (!vis[i]){vis[i]=true ,b=i;break ;} if (str[a]==str[b]&&(str[a]!=' ' &&str[b]!=' ' )) ok=true ; vis[a]=vis[b]=false ; return ; } for (int i=1 ;i<=12 &&!ok;i++) if (!vis[i]) for (int j=i+1 ;j<=13 &&!ok;j++) if (!vis[j]) for (int k=j+1 ;k<=14 &&!ok;k++){ if (!vis[k]) if ((str[i]==str[j]&&str[j]==str[k])||(str[i]+1 ==str[j]&&str[j]+1 ==str[k])){ vis[i]=vis[j]=vis[k]=true ; dfs(cur+3 ,str,cnt+1 ); vis[i]=vis[j]=vis[k]=false ; } } } int main () { int t; scanf ("%d" ,&t); while (t--){ scanf ("%s" ,&a[1 ]); int tt_=0 ; ok=false ; memset (ttt,0 ,sizeof (ttt)); for (int i=1 ;i<=14 ;i++){ ttt[a[i]-'0' ]++; if (ttt[a[i]-'0' ]>4 ){ printf ("The data is error!\n" ); tt_=1 ; break ; } } if (tt_)continue ; sort(a+1 ,a+15 ); dfs(0 ,a,0 ); if (!ok)printf ("NO\n" ); else printf ("YES\n" ); } return 0 ; }
未经允许不得转载: Anoyer's Blog » 河南农业大学热身赛标程
热评话题