比赛 |
20191022轻松模拟测试 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Rotate Columns |
最终得分 |
100 |
用户昵称 |
rainy |
运行时间 |
0.036 s |
代码语言 |
C++ |
内存使用 |
13.77 MiB |
提交时间 |
2019-10-22 19:24:59 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long int_t;
char getch(){ static char buf[100000],*s1,*s2; return (s1 == s2) && (s2 = (s1 = buf) + fread(buf,1,100000,stdin)),s1 == s2 ? EOF : *s1++; }
int_t read(){
int_t x = 0, w = 1;char ch = 0;
while(!isdigit(ch)) {ch = getch(); if(ch == '-') w = -1;}
while(isdigit(ch)) x = x * 10 + ch - '0', ch = getch();
return x * w;
}
void work1(int_t m){
int_t ans = 0;
for(int_t i=1;i<=m;i++) ans = max(ans,read());
printf("%lld\n",ans);
}
void work2(int_t m){
int_t ans1 = 0,ans2 = 0;
for(int_t i=1;i<=m * 2;i++){
int_t x = read();
if(x > ans1) ans2 = ans1, ans1 = x;
else if(x > ans2) ans2 = x;
}
printf("%lld\n",ans1 + ans2);
}
void work3(int_t m){
int_t ans1 = 0,ans2 = 0,ans3 = 0;
for(int_t i=1;i<=m*3;i++){
int_t x = read();
if(x > ans1) ans3 = ans2, ans2 = ans1, ans1 = x;
else if(x > ans2) ans3 = ans2, ans2 = x;
else if(x > ans3) ans3 = x;
}
printf("%lld\n",ans1+ans2+ans3);
}
struct P{int_t x,y,z; P(int_t x=0,int_t y=0,int_t z=0):x(x),y(y),z(z){}};
bool cmp(P a,P b){
if(a.z == b.z)
if(a.x == b.x) return a.y < b.y;
else return a.x < b.x;
else return a.z > b.z;
}
P ps[444];
int_t tmp[400];
bool pending(P a,P b,P c,P d){
memset(tmp,0,sizeof tmp);
tmp[a.y]++; tmp[b.y]++; tmp[c.y]++; tmp[d.y]++;
for(int_t i=1;i<=100;i++) if(tmp[i] == 1) return true;
if(a.y != b.y) swap(b,(a.y == c.y) ? c : d);
if(a.x > b.x) swap(a,b); if(c.x > d.x) swap(c,d);
int_t x = b.x - a.x,y = d.x - c.x;
return x == y;
}
void work4(int_t m){
sort(ps+1,ps+4*m+1,cmp);
int_t ans = 0;
if(pending(ps[1],ps[2],ps[3],ps[4]))ans=max(ans,ps[1].z+ps[2].z+ps[3].z+ps[4].z);
if(pending(ps[1],ps[2],ps[3],ps[5]))ans=max(ans,ps[1].z+ps[2].z+ps[3].z+ps[5].z);
if(pending(ps[1],ps[2],ps[3],ps[6]))ans=max(ans,ps[1].z+ps[2].z+ps[3].z+ps[6].z);
if(pending(ps[1],ps[2],ps[3],ps[7]))ans=max(ans,ps[1].z+ps[2].z+ps[3].z+ps[7].z);
if(pending(ps[1],ps[2],ps[4],ps[5]))ans=max(ans,ps[1].z+ps[2].z+ps[4].z+ps[5].z);
if(pending(ps[1],ps[2],ps[4],ps[6]))ans=max(ans,ps[1].z+ps[2].z+ps[4].z+ps[6].z);
if(pending(ps[1],ps[2],ps[4],ps[7]))ans=max(ans,ps[1].z+ps[2].z+ps[4].z+ps[7].z);
if(pending(ps[1],ps[2],ps[5],ps[6]))ans=max(ans,ps[1].z+ps[2].z+ps[5].z+ps[6].z);
if(pending(ps[1],ps[2],ps[5],ps[7]))ans=max(ans,ps[1].z+ps[2].z+ps[5].z+ps[7].z);
if(pending(ps[1],ps[2],ps[6],ps[7]))ans=max(ans,ps[1].z+ps[2].z+ps[6].z+ps[7].z);
if(pending(ps[1],ps[3],ps[4],ps[5]))ans=max(ans,ps[1].z+ps[3].z+ps[4].z+ps[5].z);
if(pending(ps[1],ps[3],ps[4],ps[6]))ans=max(ans,ps[1].z+ps[3].z+ps[4].z+ps[6].z);
if(pending(ps[1],ps[3],ps[4],ps[7]))ans=max(ans,ps[1].z+ps[3].z+ps[4].z+ps[7].z);
if(pending(ps[1],ps[3],ps[5],ps[6]))ans=max(ans,ps[1].z+ps[3].z+ps[5].z+ps[6].z);
if(pending(ps[1],ps[3],ps[5],ps[7]))ans=max(ans,ps[1].z+ps[3].z+ps[5].z+ps[7].z);
if(pending(ps[1],ps[3],ps[6],ps[7]))ans=max(ans,ps[1].z+ps[3].z+ps[6].z+ps[7].z);
if(pending(ps[1],ps[4],ps[5],ps[6]))ans=max(ans,ps[1].z+ps[4].z+ps[5].z+ps[6].z);
if(pending(ps[1],ps[4],ps[5],ps[7]))ans=max(ans,ps[1].z+ps[4].z+ps[5].z+ps[7].z);
if(pending(ps[1],ps[4],ps[6],ps[7]))ans=max(ans,ps[1].z+ps[4].z+ps[6].z+ps[7].z);
if(pending(ps[1],ps[5],ps[6],ps[7]))ans=max(ans,ps[1].z+ps[5].z+ps[6].z+ps[7].z);
if(pending(ps[2],ps[3],ps[4],ps[5]))ans=max(ans,ps[2].z+ps[3].z+ps[4].z+ps[5].z);
if(pending(ps[2],ps[3],ps[4],ps[6]))ans=max(ans,ps[2].z+ps[3].z+ps[4].z+ps[6].z);
if(pending(ps[2],ps[3],ps[4],ps[7]))ans=max(ans,ps[2].z+ps[3].z+ps[4].z+ps[7].z);
if(pending(ps[2],ps[3],ps[5],ps[6]))ans=max(ans,ps[2].z+ps[3].z+ps[5].z+ps[6].z);
if(pending(ps[2],ps[3],ps[5],ps[7]))ans=max(ans,ps[2].z+ps[3].z+ps[5].z+ps[7].z);
if(pending(ps[2],ps[3],ps[6],ps[7]))ans=max(ans,ps[2].z+ps[3].z+ps[6].z+ps[7].z);
if(pending(ps[2],ps[4],ps[5],ps[6]))ans=max(ans,ps[2].z+ps[4].z+ps[5].z+ps[6].z);
if(pending(ps[2],ps[4],ps[5],ps[7]))ans=max(ans,ps[2].z+ps[4].z+ps[5].z+ps[7].z);
if(pending(ps[2],ps[4],ps[6],ps[7]))ans=max(ans,ps[2].z+ps[4].z+ps[6].z+ps[7].z);
if(pending(ps[2],ps[5],ps[6],ps[7]))ans=max(ans,ps[2].z+ps[5].z+ps[6].z+ps[7].z);
if(pending(ps[3],ps[4],ps[5],ps[6]))ans=max(ans,ps[3].z+ps[4].z+ps[5].z+ps[6].z);
if(pending(ps[3],ps[4],ps[5],ps[7]))ans=max(ans,ps[3].z+ps[4].z+ps[5].z+ps[7].z);
if(pending(ps[3],ps[4],ps[6],ps[7]))ans=max(ans,ps[3].z+ps[4].z+ps[6].z+ps[7].z);
if(pending(ps[3],ps[5],ps[6],ps[7]))ans=max(ans,ps[3].z+ps[5].z+ps[6].z+ps[7].z);
if(pending(ps[4],ps[5],ps[6],ps[7]))ans=max(ans,ps[4].z+ps[5].z+ps[6].z+ps[7].z);
printf("%lld\n",ans);
}
void work(){
int_t n = read(),m = read();
if(n == 1)work1(m);
else if(n == 2) work2(m);
else if(n == 3) work3(m);
else {for(int_t i=1;i<=4;i++)
for(int_t j=1;j<=m;j++)
ps[(i-1)*m+j] = P(i,j,read());work4(m);}
}
int main(){
freopen("happygameT1.in","r",stdin);
freopen("happygameT1.out","w",stdout);
int_t T = read();
while(T--)work();
}