37 条题解
-
5
Fop_zz LV 10 @ 8 年前
妈的50的范围吓的我一愣
。。。。。
好好的O(n)贪心题跑你mmp的网络流。。。 -
17 年前@
-
111 年前@
用一个逗比的方法水过了,拆点,如果男女相互喜欢就原来的点连在一起,如果不喜欢就把两个拆出来的点连在一起,男生连拆出来的点一个容量为k的边,女生拆出来的点连女生原点一个容量为k的边,然后男生连s点一条容量为1,女生连t点一条容量为1,然后跑最大流,如果流量为n就方案数+1,然后再把s连男生的边容量重新改为1,女生连t的边容量重新改为1,重新跑一次。直到流量<n,这时输出方案数就是答案了&……
测试数据 #0: Accepted, time = 0 ms, mem = 4260 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 4264 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 4260 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 4264 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 4260 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 4260 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 4264 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 4260 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 4256 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 4264 KiB, score = 10
Accepted, time = 30 ms, mem = 4264 KiB, score = 100 -
08 年前@
测试数据 #0: Accepted, time = 0 ms, mem = 1552 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 1552 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 1556 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 1556 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 1564 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 1696 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 1700 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 1832 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 1832 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 1832 KiB, score = 10
Accepted, time = 30 ms, mem = 1832 KiB, score = 100
代码三次TLE到处找地方优化。。然后发现是数组开小了。。可开小了居然不是RE而是TLE这是什么情况。。。
感谢dalao们给的思路,网络流的话建模方法在下面的注释里。。
还有很长的路啊。。 -
0
-
09 年前@
P1521跳舞Accepted
记录信息
评测状态 Accepted
题目 P1521 跳舞
递交时间 2016-01-08 21:22:38
代码语言 C++
评测机 ShadowShore
消耗时间 30 ms
消耗内存 12352 KiB
评测时间 2016-01-08 21:22:40
评测结果
编译成功foo.cpp: In function 'bool bfs()':
foo.cpp:44:58: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( register int i = 0 ; i < linker[ now ].size() ; i++ )
^
foo.cpp: In function 'int dinic(int, int)':
foo.cpp:54:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( register int i = cur[ now ] ; i < linker[ now ].size() ; i++ )
^
foo.cpp: In function 'bool check(int)':
foo.cpp:77:46: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
while( bfs() ) while( temp = dinic( s , inf ) ) ans += temp;
^
测试数据 #0: Accepted, time = 0 ms, mem = 12304 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 12304 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 12312 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 12312 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 12308 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 12336 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 12328 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 12352 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 12352 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 12336 KiB, score = 10
Accepted, time = 30 ms, mem = 12352 KiB, score = 100
代码
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <string.h>
#define s 0
#define t 208
#define inf 1000000000using namespace std;
struct edge
{
int x , y , cap;
edge() {}
edge( int x , int y , int z ) : x( x ) , y( y ) , cap( z ) {}
}e[1000000];int n , k , pos , x , y , z;
vector < int > linker[200 + 10];
int ans , l , r , mid;
int dist[200 + 10] , cur[200 + 10];
char sd[50 + 2];inline void addedge( int x , int y , int z )
{
linker[ x ].push_back( pos );
e[ pos++ ] = edge( x , y , z );
linker[ y ].push_back( pos );
e[ pos++ ] = edge( y , x , 0 );
}inline bool bfs()
{
queue < int > q;
q.push( s );
memset( dist , -1 , sizeof( dist ) );
memset( cur , 0 , sizeof( cur ) );
int now;
dist[s] = 0;
while( !q.empty() )
{
now = q.front() , q.pop();
for( register int i = 0 ; i < linker[ now ].size() ; i++ )
if( dist[ e[ linker[ now ][i] ].y ] == -1 && e[ linker[ now ][i] ].cap ) q.push( e[ linker[ now ][i] ].y ) , dist[ e[ linker[ now ][i] ].y ] = dist[ now ] + 1;
}
return dist[ t ] > 0;
}inline int dinic( int now , int low )
{
if( now == t || !low ) return low;
int temp;
for( register int i = cur[ now ] ; i < linker[ now ].size() ; i++ )
{
cur [ now ] = i;
if( dist[ e[ linker[ now ][i] ].y ] == dist[ now ] + 1 && e[ linker[ now ][i] ].cap && ( temp = dinic( e[ linker[ now ][i] ].y , min( low , e[ linker[ now ][i] ].cap ) ) ) )
{
e[ linker[ now ][i] ].cap -= temp;
e[ linker[ now ][i] ^ 1 ].cap += temp;
return temp;
}
}
return 0;
}inline bool check( int x )
{
int now = 0;
for( register int i = 1 ; i <= n << 1 ; i++ )
e[ now ].cap = x , e[ now ^ 1 ].cap = 0 , now += 2;
for( register int i = 1 ; i <= n << 1 ; i++ )
e[ now ].cap = k , e[ now ^ 1 ].cap = 0 , now += 2;
for( register int i = now ; i < pos ; i += 2 )
e[i].cap = 1 , e[i ^ 1].cap = 0;
int ans = 0 , temp;
while( bfs() ) while( temp = dinic( s , inf ) ) ans += temp;
return ans >= x * n;
}int main()
{
scanf( "%d %d", &n , &k );
for( register int i = 1 ; i <= n ; i++ ) addedge( s , i , 0 );
for( register int i = 1 ; i <= n ; i++ ) addedge( n + i , t , 0 );
for( register int i = 1 ; i <= n ; i++ ) addedge( i , i + 105 , k );
for( register int i = 1 ; i <= n ; i++ ) addedge( i + n + 105 , i + n , k );
for( register int i = 1 ; i <= n ; i++ )
{
scanf( "%s", sd );
for( register int j = 1 ; j <= n ; j++ )
if( sd[j - 1] == 'Y' ) addedge( i , j + n , 1 );
else addedge( i + 105 , j + n + 105 , 1 );
}
l = 0 , r = 50 + 2;
while( l <= r )
{
mid = ( l + r ) >> 1;
if( check( mid ) ) ans = mid , l = mid + 1;
else r = mid - 1;
}
cout << ans << endl;
return 0;
} -
011 年前@
这道题有两种解法,一种贪心,一种网络流。貌似如果改成单向就要网络流。。
编译成功foo.cpp: In function 'int main()':
foo.cpp:20:22: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[51]' [-Wformat]
测试数据 #0: Accepted, time = 0 ms, mem = 432 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 436 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 436 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 432 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 440 KiB, score = 10
Accepted, time = 0 ms, mem = 444 KiB, score = 100
贪心很短。。。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>using namespace std;
#define MAXN 51
int girl[MAXN],boy[MAXN];
int n,k;
char c[MAXN];
int ans=0x7fffffff;int main(){
memset(girl,0,sizeof(girl));
memset(boy,0,sizeof(boy));
scanf("%d%d",&n,&k);
for (int i=0;i++<n;){
scanf("%s",&c);
for (int j=0;j<n;j++){
if (c[j]=='Y'){
boy[i]++;
girl[j+1]++;
}
}
}
for (int i=0;i++<n;){
ans=min(ans,girl[i]);
ans=min(ans,boy[i]);
}
ans+=k;
ans=min(ans,n);
printf("%d\n",ans);
return 0;
} -
014 年前@
这种水题我都不想说了
-
014 年前@
SAP缓缓慢慢的水过了
-
015 年前@
水题……枚举答案……然后SAP即可……
数据竟然如此之弱……编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
015 年前@
枚举答案时只要在之前的残量网络上修改一些边的容量即可,应该比每次都重新建图要快的多吧
我这样做用邻接矩阵dinic秒杀 -
015 年前@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms拆了点。。竟然 maxn 还是赋值成 50 。。。 晕。
-
015 年前@
郁闷数组赋值这步啊啊,太慢了……
于是乎……
朴素网络流=超时,加N次小优化=
Accepted 有效得分:100 有效耗时:741ms
不服气,就写个Dicinic试试,虽然数组赋值频率好像更高...
可是结果是 Accepted 有效得分:100 有效耗时:0ms看来还是不能怕麻烦……Dicnic万岁~~
-
015 年前@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms数据好弱啊,没限制K还能过9个。。。
-
015 年前@
一条件露了 弄了我一晚上
没看到女孩也最多愿意和不喜欢的男孩跳k次,以为只有男孩最多愿意和女孩跳k次
我说怎么都拆4个点
害我拆3个点的弄了一晚上还在80 -
015 年前@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 805ms
├ 测试数据 09:答案正确... 165ms
├ 测试数据 10:答案正确... 40ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:1010ms这种题目用了这么长时间,无语中………………
枚举答案真的那么慢吗 ⊙﹏⊙b
可能是因为偷懒用邻接矩阵的关系…………补充:方法:最大流+枚举答案限流
-
015 年前@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
直接模拟都0ms秒杀,可见数据之弱。 -
015 年前@
我快要崩溃了,调了N久
终于调出来了
采用了DD牛的多叉增广。。。
不过由于是用邻接矩阵写的,所以效率不是很高
一开始想用指针写,可是由于这一道题目需要多次调用原来的流网络,所以放弃了,不知各位大牛有没有办法,Orz OrzOrzOrzOrzOrzOrzOrzOrz编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
015 年前@
我算长见识了,原来过8个点的程序也可能是完全错的
-
015 年前@
program li;
var n,min,k,i,j:longint;
s:array[0..1500] of string;
boy,gril:array[0..1500] of longint;
begin
readln(n,k);
for i:= 1 to n do readln(s[i]);
for i:= 1 to n do begin boy[i]:=0; gril[i]:=0; end;for i:= 1 to n do
for j:= 1 to n do
if s[i][j]='Y' then
begin inc(boy[i]); inc(gril[j]); end;min:=maxlongint;
for i:= 1 to n do
if min>boy[i] then min:=boy[i];
for i:= 1 to n do
if min>gril[i] then min:=gril[i];if min+k>n then writeln(n)
else writeln(min+k);
end.