求解西电1042,看置顶帖第7页问题代码以附上。
100分怎么没人有兴趣呢。[ 本帖最后由 C_戴忠意 于 2012-11-3 22:03 编辑 ]
程序代码:#include <iostream>
using namespace std;
class Node
{
private:
int flag[1001];
int n,m;
public:
void init()
{
int j;
cin>>n>>m;
for (int i=1; i<=n; i++) flag[i]=0;
for (int i=1; i<=m; i++) flag[cin>>j,j]=1;
}
void printans()
{
int ans=0,state=0,last;
for (int i=n; i>=1; i--)
if (flag[i])
{
state++;
if (state==1) last=i;
if (state==7)
{
ans+=47+state*4+last+last;
state=0;
}
}
if (state!=0) ans+=47+state*4+last+last;
state=0;
for (int i=n; i>=1; i--)
if (!flag[i])
{
state++;
if (state==1) last=i;
if (state==7)
{
ans+=47+state*4+last+last;
state=0;
}
}
if (state!=0) ans+=47+state*4+last+last;
cout<<ans<<endl;
}
};
int main()
{
int time;
Node p;
cin>>time;
while (time--)
{
p.init();
p.printans();
}
}