F.A.Qs Home ProblemSet Status Ranklist 1 Contest LoginRegister
Notice:1:五月份月赛定于5.27日12:30--17:30,鸣谢Claris主持!欢迎大家来玩! 2:关于OJ的注册可看https://www.lydsy.com/JudgeOnline/wttl/thread.php?tid=5671
大视野在线测评-欢迎您
[ New Thread ]
Problem 1000 >> 我女装学搜索又TLE又WA又RE ,谁能帮我看看
jloi_yyc @ 2018-01-17 11:20:25
[ Quote ] [ Edit ] [ Delete ] 1#
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define lowbit(x) (x)&(-x)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
bool start=false,neg=false;
char c;
num=0;
while((c=getchar())!=EOF) {
if(c=='-') start=neg=true;
else if(c>='0' && c<='9') {
start=true;
num=num*10+c-'0';
} else if(start) break;
}
if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=20;
int cnt[maxn];
int res;
void dfs(int x) {
if(x>=res) return;
int temp=x;
int s1,s2,s3,t1,t2,t3; //3种顺子的首尾
s1=s2=s3=t1=t2=t3=3;
REP(i,3,15) {
if(cnt[i]) {
t1=i; //单顺子
if(t1-s1>=4 && i<15) REP(j,s1,t1-4) {
REP(k,j,t1) cnt[k]--;
dfs(x+1);
REP(k,j,t1) cnt[k]++;
}
} else s1=i+1;
if(cnt[i]>=2) {
t2=i; //双顺子
if(t2-s2>=2 && i<15) REP(j,s2,t2-2) {
REP(k,j,t2) cnt[k]-=2;
dfs(x+1);
REP(k,j,t2) cnt[k]+=2;
}
} else s2=i+1;

if(cnt[i]>=3) {
t3=i; //三顺子
if(t3-s3>=1 && i<15) REP(j,s3,t3-1) {
REP(k,j,t3) cnt[k]-=3;
dfs(x+1);
REP(k,j,t3) cnt[k]+=3;
}
cnt[i]-=3;
REP(j,3,17) if(i!=j && cnt[j]>=1) { //三带一
cnt[j]--;
dfs(x+1);
cnt[j]++;
}
REP(j,3,15) if(i!=j && cnt[j]>=2) { //三带二
cnt[j]-=2;
dfs(x+1);
cnt[j]+=2;
}
cnt[i]+=3;
} else s3=i+1;
if(cnt[i]>=4) {
cnt[i]-=4;
REP(j,3,17) if(i!=j && cnt[j]>=1) //四带二(单)
REP(k,3,17) if(i!=k && cnt[k]>=1) {
cnt[j]--;cnt[k]--;
dfs(x+1);
cnt[j]++;cnt[k]++;
}
REP(j,3,15) if(i!=j && cnt[j]>=2) //四带二(对)
REP(k,3,15) if(i!=k && cnt[k]>=2) {
cnt[j]-=2;cnt[k]-=2;
dfs(x+1);
cnt[j]+=2;cnt[k]+=2;
}
cnt[i]+=4;
}
}
if(cnt[16] && cnt[17]) { //火箭特判
cnt[16]--;cnt[17]--;
dfs(x+1);
cnt[16]++;cnt[17]++;
}
REP(i,3,17) if(cnt[i]) temp++;
res=min(res,temp);
}

int main() {
int T,n;
read(T);
read(n);
while(T--) {
memset(cnt,0,sizeof(cnt));
res=14;
int a,b;
REP(i,1,n) {
read(a);
read(b);
if(a==0) cnt[15+b]++;
else if(a<=2) cnt[a+13]++;
else cnt[a]++;
}
dfs(0);
printf("%d\n",res);
}
return 0;
}
YuhangQ @ 2018-01-17 11:22:21
[ Quote ] [ Edit ] [ Delete ] 2#
沙发
lkhlkh @ 2018-01-17 11:22:56
[ Quote ] [ Edit ] [ Delete ] 3#
洋芋叉叉!
yycc @ 2018-01-17 11:23:07
[ Quote ] [ Edit ] [ Delete ] 4#
你们有毒
lkhlkh @ 2018-01-17 11:25:22
[ Quote ] [ Edit ] [ Delete ] 5#
楼上是妹子
GXZIegend @ 2018-01-17 12:36:22
[ Quote ] [ Edit ] [ Delete ] 6#
后排吃瓜
oscar2001 @ 2018-02-12 21:18:54
[ Quote ] [ Edit ] [ Delete ] 7#
您好,为什么要强调您女装呢?
Bill_Yang @ 2018-02-26 14:54:03
[ Quote ] [ Edit ] [ Delete ] 8#
您好,为什么要强调您女装呢?
Labelray @ 2018-02-26 16:49:45
[ Quote ] [ Edit ] [ Delete ] 9#
您好,为什么要强调您女装呢?
jjikkollp @ 2018-02-26 17:36:50
[ Quote ] [ Edit ] [ Delete ] 10#
您好,为什么要强调您女装呢?
EdwardFrog @ 2018-02-26 17:54:48
[ Quote ] [ Edit ] [ Delete ] 11#
那你看
TechCiel @ 2018-02-26 19:01:56
[ Quote ] [ Edit ] [ Delete ] 12#
您好,为什么要强调您女装呢?
MayBe @ 2018-02-26 19:08:46
[ Quote ] [ Edit ] [ Delete ] 13#
讲道理这份代码能a,为什么不去找个又TLE又WA又RE的好。
yycc @ 2018-02-27 07:53:09
[ Quote ] [ Edit ] [ Delete ] 14#
那你男装试试
YuhangQ @ 2018-02-28 07:18:01
[ Quote ] [ Edit ] [ Delete ] 15#
您好,为什么要强调您女装呢?
tangyunkai1 @ 2018-02-28 13:28:58
[ Quote ] [ Edit ] [ Delete ] 16#
代码明显没有问题,你是怎么WA的。。
Michael_Bryant @ 2018-02-28 13:45:40
[ Quote ] [ Edit ] [ Delete ] 17#
原来你的逻辑是样例过了就是A了啊。。。自己看看原题数据范围。。。再不懂就别做了吧 = =+
EdwardFrog @ 2018-02-28 15:49:09
[ Quote ] [ Edit ] [ Delete ] 18#
@GXZlegend
数据范围的话数组大小我试过用50000,变量我能想到的只有long int也不行所以上面程序才用的int和cnt[20];
我整个程序虽然现在无法AC但逻辑并没有错,我诚心诚意地发问了,你不说也就算了,用个puts吐槽我又是要作甚?
tonyfag @ 2018-02-28 16:08:55
[ Quote ] [ Edit ] [ Delete ] 19#
LS 鄙视GXZlegend蒟蒻涨rp……
建议去学c或c++再来捉此题~
liudailiusuanna @ 2018-03-03 13:13:54
[ Quote ] [ Edit ] [ Delete ] 20#
哈哈哈 这个题确实可以在一道数据增强版的上面TLE
[Top] [Previous Page] [Next Page]

HOME Back