挺坑爹的。。。只怪自己能力不行吧。。。
贴最水的两题。。。
1102:此题先转换题意,求所给的蜡烛最少多少次全部点燃。。证明就算了。。。然后发现,从外往前,只要没点燃的必定要点燃。。
比如:
4
1000
0110
0110
0001
搜索顺序:
tmpx = 1 tmpy = 4
tmpx = 1 tmpy = 3
tmpx = 2 tmpy = 4
tmpx = 1 tmpy = 2
tmpx = 2 tmpy = 3
tmpx = 3 tmpy = 4
tmpx = 4 tmpy = 1
tmpx = 3 tmpy = 1
tmpx = 4 tmpy = 2
tmpx = 2 tmpy = 1
tmpx = 3 tmpy = 2
tmpx =1 tmpy = 1
tmpx = 2 tmpy = 2
tmpx = 3 tmpy =3
tmpx = 4 tmpy = 4
然后,分两部分进行记录,此行和此列改变过多少次。即:
int row[1025][2],lie[1025][2];
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
using namespace std;
int a[1025][1025];
int n;
int c;
int main()
{
int i,j,k;
int tmpx=1,tmpy=n-i+1;
char s[1500];
int row[1025][2],lie[1025][2];
while(scanf("%d",&n)!=EOF)
{
c = 0;
for(i = 1;i<=n;i++)
{
scanf("%s",s+1);
for(j = 1;j<=n;j++)
{
a[i][j] = (s[j]-'0');
}
row[i][0] = lie[i][0] = 0;
row[i][1] = lie[i][1] = 0;
}
for(i = 1;i<n;i++)
{
tmpx=1,tmpy=n-i+1;
for(j = 1;j<=i;j++)
{
if((a[tmpx][tmpy]+row[tmpx][0]+lie[tmpy][0])%2 == 0)
{
row[tmpx][0]=1-row[tmpx][0];
lie[tmpy][0]=1-lie[tmpy][0];
c++;
}
tmpx++;
tmpy++;
}
}
for(i = 1;i<n;i++)
{
tmpx=n-i+1,tmpy=1;
for(j = 1;j<=i;j++)
{
if((a[tmpx][tmpy]+row[tmpx][1]+lie[tmpy][1])%2 == 0)
{
row[tmpx][1]=1-row[tmpx][1];
lie[tmpy][1]=1-lie[tmpy][1];
c++;
}
tmpx++;
tmpy++;
}
}
for(i = 1;i<=n;i++)
{
if((a[i][i]+row[i][0]+row[i][1]+lie[i][0]+lie[i][1])%2 == 0)
c++;
}
printf("%d\n",c);
}
return 0;
}
呵呵。 此题不解释了。。
/*************************************************************************
> File Name: 1104.cpp
> Author: withwind
> Mail: withwind93@gmail.com
> Created Time: 2013/3/10 19:23:44
************************************************************************/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int i,j,k;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&k);
int ans =1;
for( i =1;i<k;i++)
ans=ans*2;
printf("%d\n",ans);
}
return 0;
}