数据运算时候int*int不能和long long比,所有的都要开成long long!
由此可见,设计测试数据的时候还是设计大点吧,都跑一遍,要不然会死那里!
For example:
Walking Between Houses http://codeforces.com/problemset/problem/1015/D
#include
#include
#include
#include
using namespace std;
int main()
{
long long n,k,time=0,jian,now;//这里不开long long能玩死你!
long long s;
cin>>n>>k>>s;
if ((n-1)*k0)
{
if (s-n+1>=(k-1))
{
k--;
time++;
s=s-n+1;
if (time%2==1)
printf("%d ",n);
else
printf("1 ");
}
else
{
k--;
jian=s-k;
if (time%2==1)
{
printf("%d ",n-jian);
now=n-jian;
}
else
{
printf("%d ",1+jian);
now=1+jian;
}
for (int p=1;p<=k;p++)
if (p%2==1)
printf("%d ",now+1);
else
printf("%d ",now);
break;
}
}
return 0;
}
循环退出机制要设置,不要死循环,该break就break!
For example:
B - Obtaining the String http://codeforces.com/problemset/problem/1015/B
#include
#include
#include
using namespace std;
int main()
{
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
int n,tot=0,a[50],b[50],ans[10010];
char s[100],t[100];
cin>>n;
cin>>s>>t;
for (int i=0;i<=30;i++)
{
a[i]=0;
b[i]=0;
}
for (int i=0;ii;k--)
{
char temp;
temp=s[k];
s[k]=s[k-1];
s[k-1]=temp;
tot++;
ans[tot]=k;
}
break;//break break break!!!要不然会一直找
}
}
printf("%d\n",tot);
for (int i=1;i<=tot;i++)
printf("%d ",ans[i]);
return 0;
}
bool数组也要初始化,什么时候都初始化,不管初值
For example:
A - Agri-Net http://poj.org/problem?id=1258
```c++
include
include
using namespace std;
int d[110],a[110][110],n;
int prim()
{
bool visit[110];//这里你虽然是局部变量,但是初值也要设置false都
for (int i=1;i<=n;i++)
visit[i]=false;
d[1]=0;
int ans=0;
for (int i=1;i<=n;i++)
{
int u=-1,min=999999999;
for (int j=1;j<=n;j++)
{
if (visit[j]==false and d[j]
u=j;
min=d[j];
}
}
visit[u]=true;
ans+=d[u];
for (int v=1;v<=n;v++)
{
if (visit[v]==false and a[u][v]
}
}
return ans;
}
int main()
{
while (cin>>n)
{
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for (int i=1;i<=n;i++)
d[i]=999999999;
cout<
return 0;
}