较水题,手速赛。关键是看题不要看错,这样卡时间。还有手速保持在较快的水准,有意识地训练~
A 数字方阵 > 25663765
随机化生成方阵,修改直到方阵满足条件 (重复3次,都A了)
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <list> #include <stack> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <iostream> using namespace std; #define ll long long const long maxn=1e6+5; const ll mod=1e9+7; long a[1005][1005]; bool vis[100005]; long n,i,j,sum=0,x,y; set<long>f; bool check() { f.clear(); for (i=1;i<=n;i++) { sum=0; for (j=1;j<=n;j++) sum+=a[i][j]; f.insert(sum); sum=0; for (j=1;j<=n;j++) sum+=a[j][i]; f.insert(sum); } sum=0; for (i=1;i<=n;i++) sum+=a[i][i]; f.insert(sum); sum=0; for (i=1;i<=n;i++) sum+=a[i][n+1-i]; f.insert(sum); if (f.size()!=2*n+2) return false; else return true; } int main() { long p,q,x,y,temp; scanf("%ld",&n); while (1) { sum=0; for (i=1;i<=n;i++) for (j=1;j<=n;j++) { sum++; a[i][j]=sum; } for (i=1;i<=min(n*n,(long)1000);i++) { x=rand()%n+1; y=rand()%n+1; p=rand()%n+1; q=rand()%n+1; temp=a[x][y]; a[x][y]=a[p][q]; a[p][q]=temp; } if (check()) { for (i=1;i<=n;i++) { for (j=1;j<n;j++) printf("%ld ",a[i][j]); printf("%ld ",a[i][j]); } break; } } return 0; }
另:
对称结构最容易产生相同的行/列/对角线和值
但对称结构最好创建
所以创建对称结构,在这基础上进行微调
A 数字方阵 > 25713373
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <cmath> 5 #include <list> 6 #include <stack> 7 #include <vector> 8 #include <set> 9 #include <map> 10 #include <queue> 11 #include <algorithm> 12 #include <iostream> 13 using namespace std; 14 #define ll long long 15 const long maxn=1e4+5; 16 const ll mod=1e9+7; 17 18 long a[maxn][maxn]; 19 long i,j,t,n,sum; 20 set<long>f; 21 22 bool check() 23 { 24 f.clear(); 25 for (i=0;i<n;i++) 26 { 27 sum=0; 28 for (j=0;j<n;j++) 29 sum+=a[i][j]; 30 f.insert(sum); 31 printf("%ld ",sum); 32 33 sum=0; 34 for (j=0;j<n;j++) 35 sum+=a[j][i]; 36 f.insert(sum); 37 printf("%ld ",sum); 38 } 39 40 sum=0; 41 for (i=0;i<n;i++) 42 sum+=a[i][i]; 43 f.insert(sum); 44 printf("%ld ",sum); 45 46 sum=0; 47 for (i=0;i<n;i++) 48 sum+=a[i][n+1-i]; 49 f.insert(sum); 50 printf("%ld ",sum); 51 52 if (f.size()!=2*n+2) 53 return false; 54 else 55 return true; 56 } 57 58 int main() 59 { 60 scanf("%ld",&n); 61 sum=0; 62 for (i=0;i<n;i++) 63 for (j=0;j<n-1;j++) 64 { 65 sum++; 66 a[i][j]=sum; 67 } 68 for (j=0;j<n;j++) 69 { 70 sum++; 71 a[j][n-1]=sum; 72 } 73 /* 74 for (i=0;i<n;i++) 75 { 76 for (j=0;j<n;j++) 77 { 78 sum++; 79 a[i][j]=sum; 80 } 81 } 82 if (n%2==0) 83 { 84 t=a[0][n-2]; 85 a[0][n-2]=a[0][n-1]; 86 a[0][n-1]=t; 87 } 88 else 89 { 90 sum=0; 91 // 92 } 93 */ 94 for (i=0;i<n;i++) 95 { 96 for (j=0;j<n;j++) 97 { 98 printf("%ld",a[i][j]); 99 if (j==n-1) 100 printf(" "); 101 else 102 printf(" "); 103 } 104 } 105 // if (!check()) 106 // printf("F "); 107 return 0; 108 }
B 小马过河 > 25648307
想不到好方法。做了两条直线(ax+by+c=0),求交点
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <list> #include <stack> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <iostream> using namespace std; #define ll long long const long maxn=1e6+5; const ll mod=1e9+7; long double xp,yp,xu,yu,xv,yv, x,y; long double a1,b1,c1,a2,b2,c2,aa1,bb1,cc1,aa2,bb2,cc2; int main() { long t; scanf("%ld",&t); while (t--) { scanf("%llf%llf%llf%llf%llf%llf",&xp,&yp,&xu,&yu,&xv,&yv); a1=yu-yv; b1=xv-xu; c1=-a1*xu-b1*yu; a2=xu-xv; b2=yu-yv; c2=-a2*xp-b2*yp; aa1=a1*a2; bb1=b1*a2; cc1=c1*a2; aa2=a2*a1; bb2=b2*a1; cc2=c2*a1; y=(cc1-cc2)/(bb2-bb1); x=(-c1-b1*y)/a1; printf("%.7llf %.7llf ",x,y); } return 0; }
另:直接推公式
https://blog.csdn.net/sr_19930829/article/details/19825661
C 真真假假 > 25645450
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <list> #include <stack> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <iostream> using namespace std; #define ll long long const long maxn=1e6+5; const ll mod=1e9+7; char str[35][20]={"algorithm", "bitset", "cctype", "cerrno", "clocale", "cmath", "complex", "cstdio", "cstdlib", "cstring", "ctime", "deque", "exception", "fstream", "functional", "limits", "list", "map", "iomanip", "ios", "iosfwd", "iostream", "istream", "ostream", "queue", "set", "sstream", "stack", "stdexcept", "streambuf", "string", "utility", "vector", "cwchar", "cwctype"}; char s[1000]; void pan() { long i; for (i=0;i<35;i++) if (strcmp(s,str[i])==0) { printf("Qian "); return; } printf("Kun "); } int main() { long t; scanf("%ld ",&t); while (t--) { gets(s); pan(); } return 0; }
比赛时候不停“”,太傻,幸好数量不多
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <cmath> 5 #include <list> 6 #include <stack> 7 #include <vector> 8 #include <set> 9 #include <map> 10 #include <queue> 11 #include <algorithm> 12 #include <iostream> 13 using namespace std; 14 #define ll long long 15 const long maxn=1e6+5; 16 const ll mod=1e9+7; 17 18 19 int main() 20 { 21 char s[20]; 22 while (scanf("%s",s)!=EOF) 23 { 24 s[strlen(s)-1]='