scanf/printf占用时间比cin/cout少很多,用cin/cout超时了,很可能就是因为这个。如果必须要用输入输出流的话,建议在main第一行加上加速:ios :: sync_with_stdio(0); cin.tie(0);