天坑未补。。。
水一波博客,再不写博客就咸成鱼干了,只写题不写题解,过一段时间就忘了自己学过什么了。
最近重点就是把开学以来写的题补出来,没学的就滚去学会啊(= =),填一下坑。。。
从这篇博客开始,填最近的坑
先贴这些题的题解,剩下的3道题过一段时间补出来再贴。
开始表演。
A.数字方阵
链接:https://www.nowcoder.com/acm/contest/86/A
这个题是反魔方阵,正常的魔方阵是相同,这个是不相同,有一个神奇的东西,先来个传送门,biubiubiu
梁邱构造法(百度文库不让我粘贴,那我就截图,hhhhhh)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<cstdlib> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<stack> 10 using namespace std; 11 typedef long long ll; 12 const int maxn=1e5+10; 13 const double eps=1e-7; 14 int main(){ 15 int n; 16 cin>>n; 17 int cnt=1,ret=n*n-n+1; 18 for(int i=1;i<=n;i++){ 19 for(int j=1;j<=n;j++){ 20 if(j==n)cout<<ret++<<endl; 21 else cout<<cnt++<<" "; 22 } 23 } 24 }
B.小马过河
链接:https://www.nowcoder.com/acm/contest/86/B
这个题是一个简单的几何题???套个板子就过了,就是直线上两点确定的这条直线和直线外一点的垂足的坐标。
板子题,但是板子具体的操作没仔细看(嘤嘤嘤???(怕是要被锤死。。。))
板子来源:传送门
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<cstdlib> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<stack> 10 using namespace std; 11 typedef long long ll; 12 const int maxn=1e5+10; 13 const double eps=1e-7; 14 // 二维空间点到直线的垂足 15 struct Point 16 { 17 double x,y; 18 }; 19 Point GetFootOfPerpendicular(const Point &pt,const Point &begin,const Point &end){ 20 Point retVal; 21 double dx = begin.x - end.x; 22 double dy = begin.y - end.y; 23 if(abs(dx) < 0.0000000001 && abs(dy) < 0.0000000001 ){ 24 retVal = begin; 25 return retVal; 26 } 27 double u = (pt.x - begin.x)*(begin.x - end.x) + (pt.y - begin.y)*(begin.y - end.y); 28 u = u/((dx*dx)+(dy*dy)); 29 retVal.x = begin.x + u*dx; 30 retVal.y = begin.y + u*dy; 31 return retVal; 32 } 33 int main(){ 34 int t; 35 cin>>t; 36 while(t--){ 37 Point pt,begin,end; 38 cin>>pt.x>>pt.y>>begin.x>>begin.y>>end.x>>end.y; 39 Point retVal=GetFootOfPerpendicular(pt,begin,end); 40 printf("%.7f %.7f\n",retVal.x,retVal.y); 41 } 42 }
C.真真假假
链接:https://www.nowcoder.com/acm/contest/86/C
这个题真的是无敌的水,但是自己写前面的string数组的时候,里面的这些头文件要用双引号(" ")括起来,敲双引号敲到手抽筋,超级暴力的写法,还被对面的瓜皮骂了一句(嫌我操作太秀。。。)
1 //C 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<cstdlib> 7 #include<algorithm> 8 #include<queue> 9 #include<vector> 10 #include<stack> 11 using namespace std; 12 typedef long long ll; 13 const int maxn=1e5+10; 14 const double eps=1e-7; 15 string c[100]={"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"}; 16 int main(){ 17 int t; 18 cin>>t; 19 while(t--){ 20 string s; 21 cin>>s; 22 int flag=0; 23 for(int i=0;i<100;i++){ 24 if(s==c[i]){ 25 flag=1; 26 cout<<"Qian"<<endl; 27 break; 28 } 29 } 30 if(flag==0)cout<<"Kun"<<endl; 31 } 32 }
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<cstdlib> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<stack> 10 using namespace std; 11 typedef long long ll; 12 const int maxn=1e5+10; 13 const double eps=1e-7; 14 #include<stdio.h> 15 #include<string.h> 16 int q[2010],q1[2010],n; 17 int zhaodie(int a){ 18 while(q[a]!=a) 19 a=q[a]; 20 return a; 21 } 22 void merge1(int a2,int b2){ 23 int a1=zhaodie(a2); 24 int b1=zhaodie(b2); 25 if(a1!=b1){ 26 q[a1]=b1; 27 for(int i=1; i<=n; i++) 28 if(q[i]==a2||q[i]==a1) 29 q[i]=b1; 30 } 31 32 } 33 int main(){ 34 int t; 35 cin>>t; 36 while(t--){ 37 memset(q1,0,sizeof(q1)); 38 int m; 39 cin>>n>>m; 40 for(int i=1; i<=n; i++) 41 q[i]=i; 42 int u,v; 43 for(int i=0; i<m; i++){ 44 scanf("%d%d",&u,&v); 45 merge1(u,v); 46 q1[u]++; 47 q1[v]++; 48 } 49 int e=q[1]; 50 int flag=0; 51 for(int i=2; i<=n; i++){ 52 if(q[i]!=e){ 53 flag=1; 54 break; 55 } 56 } 57 int sum=0; 58 for(int i=1; i<=n; i++){ 59 if(q1[i]&1) 60 sum++; 61 } 62 if((sum==0||sum==2)&&!flag) 63 cout<<"Zhen"<<endl; 64 else 65 cout<<"Xun"<<endl; 66 } 67 return 0; 68 }
E.是是非非
链接:https://www.nowcoder.com/acm/contest/86/E
这个题就是尼姆博奕(我的队友小可爱很擅长这个)
代码:
1 //E 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<cstdlib> 7 #include<algorithm> 8 #include<queue> 9 #include<vector> 10 #include<stack> 11 using namespace std; 12 typedef long long ll; 13 const int maxn=1e5+10; 14 const double eps=1e-7; 15 int a[maxn]; 16 int main(){ 17 int n,q; 18 cin>>n>>q; 19 int ans=0; 20 for(int i=1;i<=n;i++){ 21 cin>>a[i]; 22 ans^=a[i]; 23 } 24 while(q--){ 25 int x,y; 26 cin>>x>>y; 27 ans^=a[x]; 28 a[x]=y; 29 ans^=y; 30 if(ans) 31 cout<<"Kan"<<endl; 32 else 33 cout<<"Li"<<endl; 34 } 35 }
G.文
链接:https://www.nowcoder.com/acm/contest/86/G
这个题wa了一发,有点智障,浮点数,式子里面要*1.0,忘了,然后wa了,改了就过了(脑子有坑)
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<cstdlib> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<stack> 10 using namespace std; 11 typedef long long ll; 12 const int maxn=1e5+10; 13 const double eps=1e-7; 14 15 struct node{ 16 string name; 17 char c[maxn]; 18 int num=0; 19 }a[110]; 20 21 bool cmp(node a,node b){ 22 if(a.num<b.num)return 1; 23 else if(a.num==b.num){ 24 if(a.name<b.name)return 1; 25 else return 0; 26 } 27 else return 0; 28 } 29 char s[maxn]; 30 int main(){ 31 int n,m; 32 cin>>n>>m; 33 for(int i=0;i<n;i++) 34 cin>>s[i]; 35 for(int i=0;i<m;i++){ 36 cin>>a[i].name>>a[i].c; 37 for(int j=0;j<n;j++){ 38 if(a[i].c[j]!=s[j])a[i].num++; 39 } 40 } 41 sort(a,a+m,cmp); 42 cout<<a[0].name<<endl; 43 double score=100*1.0/n*(n-a[0].num); 44 printf("%.2f\n",score); 45 }
H.武
链接:https://www.nowcoder.com/acm/contest/86/H
这个题写的有点想发脾气,自己的板子垃圾了,这个题要用优先队列优化版的迪杰斯特拉的板子才可以过,但是自己太智障了,段错误,编译错误,段错误,内存超限,运行超时,段错误,a了。
不想说什么了,简直蠢到家了。
代码(学长的板子就是好):
1 //H-学长的模板 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<cstdlib> 7 #include<algorithm> 8 #include<queue> 9 #include<vector> 10 #include<stack> 11 using namespace std; 12 typedef long long ll; 13 const int maxn=1e5+10; 14 const double eps=1e-7; 15 const int N=1e5+10; 16 const int INF=0x3f3f3f3f; 17 18 19 int head[N*2], nex[N*2], to[N*2], val[N*2], dis[N], vis[N], tot; 20 21 struct cmp{ 22 bool operator()(int a,int b) { 23 return dis[a]>dis[b]; 24 } 25 }; 26 27 priority_queue<int, vector<int>, cmp > Q; 28 29 void init() { 30 tot = 0; 31 while(!Q.empty()) Q.pop(); 32 memset(head, -1, sizeof(head)); 33 memset(dis, 127, sizeof(dis)); 34 memset(vis, 0, sizeof(vis)); 35 } 36 37 void addedge(int u, int v, int w) { 38 to[tot] = v; 39 nex[tot] = head[u]; 40 val[tot] = w; 41 head[u] = tot++; 42 } 43 44 void Dijkstra(int S) { 45 Q.push(S); 46 dis[S] = 0, vis[S] = 1; 47 while(!Q.empty()) { 48 int u = Q.top(); 49 Q.pop(); 50 for(int i=head[u]; i!=-1; i=nex[i]) { 51 int v = to[i]; 52 if(!vis[v] && dis[u]+val[i] < dis[v]) { 53 dis[v] = dis[u]+val[i]; 54 Q.push(v), vis[v] = 1; 55 } 56 } 57 } 58 } 59 60 int main(){ 61 int n,p,k; 62 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); 63 init(); 64 cin>>n>>p>>k; 65 for(int i=0;i<n-1;i++){ 66 int u,v,w; 67 cin>>u>>v>>w; 68 addedge(u,v,w); 69 addedge(v,u,w); 70 } 71 Dijkstra(p); 72 sort(dis+1,dis+1+n); 73 cout<<dis[k+1]<<endl; 74 }
就先这样吧,F,I,J比赛的时候没写出来也没时间了,还没补,F是搜索+博弈,其他两个还没看,补出来再来粘代码,我圆润的离开了(gun)。