1001
http://acm.hdu.edu.cn/showproblem.php?pid=4993
暴力一下。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int t,a,b,c;
int ans;
int main()
{
rd(t);
while(t--)
{
rd3(a,b,c);
ans=0;
for(int x=1;;x++)
{
if(a*x>c)
break;
if((c-a*x)%b==0&&(c-a*x)/b!=0)
ans++;
}
cout<<ans<<endl;
}
return 0;
}
1002
http://acm.hdu.edu.cn/showproblem.php?pid=4994
博弈题。题意为有n堆石子,每堆有一定数量的石子,规则为从第一堆开始拿,每个人可以拿一堆里面的任意多个,当第一堆石子全部拿完后,才可以拿第二堆,最后一次拿的为胜,问先手是否能胜。
关键点:谁先取得石子数量大于1的那堆的拿取优先权,谁胜,也就是先求这n堆里面前面有连续的几堆数量为1,设有连续的cnt堆,一堆只有1个,肯定会拿走着一个,当cnt是偶数时,拿完这些数量为1的堆,下一次还是先手先拿,那么他就可以控制自己再拿到下一次的数量大于1的那堆的拿取优先权。 比如 4 1 1 2,先手可以拿3个,那么后手只能拿剩下的1个,然后先手拿1个,后手再拿一个,先手获得数量为2的那堆的拿取优先权,直接全拿走获胜,再比如 4 1 2,那么先手把4全拿走,后手拿走1个,先手照样获得2那堆的优先权,因此谁先获取数量大于1的那堆的拿取优先权,谁就可以掌控整个局面,获胜。
当然给定的n堆里每堆全部是1的情况也要考虑,这下就要判断n是奇数还是偶数了,每堆都为1,只能轮流拿一个。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
//谁先拿到了第一个大于1的那一堆,谁就赢
const int maxn=1010;
int num[maxn];
int n;
bool has;//是否存在大于1的那一堆
int cnt;
int main()
{
int t;
rd(t);
while(t--)
{
rd(n);
cnt=0;has=0;
for(int i=1;i<=n;i++)
rd(num[i]);
for(int i=1;i<=n;i++)
{
if(num[i]==1)
cnt++;
else
{
has=1;
break;
}
}
if(!has)//当不存在大于1的堆时
{
if(cnt&1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
{
if(cnt&1)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=4995
模拟题...题意貌似说的不够清楚..输入的点不是按位置从小到大给定的....
看的网上的代码...
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=100010;
int N,M,K;
int adj[maxn][12];
struct P
{
int id;//输入过程中的id
int x;
}point[maxn];
double v[maxn];
bool cmp(P a,P b)
{
return a.x<b.x;
}
bool left_ok(int L,int R,int th)
{
if(L<=0)
return false;
if(R>N)
return true;
if(point[th].x-point[L].x!=point[R].x-point[th].x)
return (point[th].x-point[L].x)<(point[R].x-point[th].x);
return point[L].id<point[R].id;
}
void get_knn(int th)
{
int id=point[th].id;
int L=th-1,R=th+1;
for(int i=1;i<=K;i++)
{
if(left_ok(L,R,th))
adj[id][i]=point[L--].id;
else
adj[id][i]=point[R++].id;
}
}
int main()
{
int t;
rd(t);
while(t--)
{
rd3(N,M,K);
for(int i=1;i<=N;i++)
{
scanf("%d%lf",&point[i].x,&v[i]);
point[i].id=i;//这时的id也就是等于要查询的id
}
sort(point+1,point+1+N,cmp);
for(int i=1;i<=N;i++)
get_knn(i);
double ans=0.0;
int x;
while(M--)
{
rd(x);
double tp=0.0;
for(int j=1;j<=K;j++)
tp+=v[adj[x][j]];//V[]输入过程中的编号..
v[x]=tp/K;
ans+=v[x];
}
printf("%.6lf\n",ans);
}
return 0;
}