• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LyonLys
愿意在角落唱沙哑的歌 再大声也都是给你 请用心听 不要说话 Contact me via E-mail: lyon.lys@gmail.com
博客园    首页    新随笔    联系   管理    订阅  订阅

hdu 1496 Equations

http://acm.hdu.edu.cn/showproblem.php?pid=1496

  上一题hash的升级版,不过还是简单题..只能当作是练手了...

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 
 5 const int maxn = 50007;
 6 int hash[maxn], cnt[maxn];
 7 int tx[101];
 8 
 9 void pre(){
10     for (int i = 1; i <= 100; i++){
11         tx[i] = i * i;
12     }
13 }
14 
15 void init(){
16     memset(cnt, 0, sizeof(cnt));
17 }
18 
19 void insert(int a){
20     int p = (a << 3) % maxn;
21 
22     if (p < 0) p += maxn;
23     while (hash[p] != a && cnt[p]) p = (p + 1) % maxn;
24     hash[p] = a;
25     cnt[p]++;
26 }
27 
28 int count(int a){
29     int p = (a << 3) % maxn;
30 
31     if (p < 0) p += maxn;
32     while (hash[p] != a && cnt[p]) p = (p + 1) % maxn;
33 
34     return cnt[p];
35 }
36 
37 int main(){
38     int a, b, c, d;
39 
40     pre();
41     while (~scanf("%d%d%d%d", &a, &b, &c, &d)){
42         init();
43         if ((a < 0 && b < 0 && c < 0 && d < 0) || (a > 0 && b > 0 && c > 0 && d > 0)){
44             puts("0");
45             continue;
46         }
47         for (int i = 1; i <= 100; i++){
48             for (int j = 1; j <= 100; j++){
49                 insert(a * tx[i] + b * tx[j]);
50             }
51         }
52         int tt = 0;
53 
54         for (int i = 1; i <= 100; i++){
55             for (int j = 1; j <= 100; j++){
56                 tt += count(- (c * tx[i] + d * tx[j]));
57             }
58         }
59         printf("%d\n", tt << 4);
60     }
61 
62     return 0;
63 }

 

——written by Lyon

posted @ 2012-09-04 12:26  LyonLys  阅读(145)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3