3 条题解
-
3
仅仅记录(7.13)
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; const int N = 1e5+10; map<PII,int> p_c; map<PII,bool> p_op; // int g[N][N]; int r,c,n,m,cnt; PII error = {-1,-1}; PII move(PII p,char op) { if(op == 'U') return {p.first-1,p.second}; else if(op == 'D') return {p.first+1,p.second}; else if(op == 'L') return {p.first,p.second-1}; else if(op == 'R') return {p.first,p.second+1}; } bool is_vaild(PII p,char op1,char op2) { if(p_c[move(p,op1)] == p_c[move(p,op2)] && p_c[move(p,op1)] && p_c[move(p,op2)]) return true; else return false; } void print(PII p) { cout << p.first << " " << p.second << " " << p_c[p] << endl; } int main() { cin >> r >> c; cin >> n; int a,b,c,d; for(int i=1;i<=n;i++) { cin >> a >> b >> c >> d; // g[a][b] = i; // g[c][d] = i; p_c[{a,b}] = i; p_c[{c,d}] = i; p_op[{a,b}] = true; p_op[{c,d}] = true; } cin >> m; for(int i=1;i<=m;i++) { int x,y; char op1,op2; cin >> x >> y >> op1 >> op2; cout << endl; print({x,y}); print(move({x,y},op1)); print(move({x,y},op2)); cout << endl; if(is_vaild({x,y},op1,op2) && p_op[move({x,y},op1)] && p_op[move({x,y},op2)]) { cnt+=2; p_op[move({x,y},op1)] = false; p_op[move({x,y},op2)] = false; } } cout << cnt; return 0; }
-
1
#include #include #include using namespace std; int n,x[10005],y[10005],ans=0,rx,ry; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",x+i,y+i); sort(x+1,x+n+1); sort(y+1,y+n+1); for(int i=1;i<=n;i++) x[i]-=i; sort(x+1,x+n+1); if(!n%2) { rx=(x[n/2]+x[n/2+1])/2; ry=(y[n/2]+y[n/2+1])/2; } else { rx=x[n/2+1]; ry=y[n/2+1]; } for(int i=1;i<=n;i++) ans+=abs(x[i]-rx)+abs(y[i]-ry); printf("%d",ans); return 0; }
- 1
信息
- ID
- 2
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 141
- 已通过
- 4
- 上传者