BestCoder Valentine's Day Round

  昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法)。

  1001,也就是 hdu 5174,题意很难叙述了,自己看题吧,这题有数据溢出的风险,我竟然是AC了一发才发觉的(只过了小数据),幸好后来改后赶紧再交一遍才不至于被人hack,因为需要对数据去重,我不想用数组模拟,便尝试下用 map了,可是我的奇葩 map ( ~′⌒`~),连我自己都感到无语了:

 1 #include<cstdio>
 2 #include<map>
 3 #include<iostream>
 4 using namespace std;
 5 typedef long long LL;
 6 const int INF= 0x7fffffff;
 7
 8 typedef map<int,int>::iterator  mit;
 9
10 mit operator +(const mit &p, int i)
11 {
12     mit it= p;
13     return ++it;
14 }
15
16 mit operator -(const mit &p, int i)
17 {
18     mit it= p;
19     return --it;
20 }
21
22 int main(){
23     int n,i,x,k= 0;
24     map<int,int> m;
25     while(~scanf("%d",&n)){
26         m.clear();
27         for(i=1; i<=n; ++i){
28             cin>>x;
29             if(m.find(x)!=m.end())  ++m[x];
30             else    m.insert(pair<int,int>(x,1));
31         }
32         if(m.size()==1) {
33             printf("Case #%d: -1\n",++k);
34             continue;
35         }
36         mit st= m.begin(), it= st, ed= m.end()-1;
37
38         int ans= 0;
39         for(++it; it!=ed; ++it)
40             if(((LL)it->first+ (it-1)->first)%INF == (it+1)->first)    ans+= it->second;
41
42         if(((LL)st->first+ ed->first)%INF== (st+1)->first)  ans+= st->second;
43         if(((ed-1)->first+ (LL)ed->first)%INF== st->first)  ans+= ed->second;
44         printf("Case #%d: %d\n",++k,ans);
45     }
46     return 0;
47 }

  上网找了下,发觉有个做法很不错的,用数组和 map一起模拟,不用什么 insert啊,find啊,还有连迭代器都不用,编码能力确实比我高多了,不得不赞:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <map>
 4 #include <algorithm>
 5 #define INT_MAX 2147483647
 6 using namespace std;
 7
 8 int main()
 9 {
10     int n, k = 1;
11     long long ans;
12     long long a[1000];
13     while(~scanf("%d", &n))
14     {
15         ans = 0;
16         map<int, int> mm;
17         int cnt = 0, tmp;
18         for(int i = 0; i < n; i++)
19         {
20             scanf("%d", &tmp);
21             if(!mm[tmp])
22             {
23                 a[cnt++] = tmp;
24             }
25             mm[tmp]++;
26         }
27         if(cnt == 1)
28         {
29             printf("Case #%d: -1\n", k++);
30             continue;
31         }
32         sort(a, a+cnt);
33         for(int i = 0 ; i < cnt; i++)
34         {
35             if((a[(i - 1 + cnt) % cnt] + a[(i - 2 + cnt) % cnt]) % INT_MAX == a[i])
36             {
37                 ans += mm[a[(i - 1 + cnt) % cnt]];
38             }
39         }
40         printf("Case #%d: %d\n", k++, ans);
41     }
42     return 0;
43 }

  1002,hdu 5175,是今天中午才做的,一开始还以为要用到什么高大上的数论定理,后来才发现不过是普通的暴力就行,枚举 n 所有的因数 i 看是否满足  gcd(n, n^i)== i 即可,真正的卡人是在输出格式上:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef long long LL;
 7
 8 LL gcd(LL a, LL b)  {  return b==0? a: gcd(b,a%b);  }
 9
10 LL digit[200000]= {1}, ans[200000];
11
12 void solve(LL n)
13 {
14     if(n==1){
15         puts("0\n");
16         return;
17     }
18     int num= 0;
19     LL m= sqrt(n+0.5);
20     for(LL i=2; i<=m; ++i)
21         if(n%i==0){
22             digit[++num]= i;
23             if(n/i!=i)  digit[++num]= n/i;
24         }
25     int c= 0;
26     for(int i=0; i<=num; ++i){
27         LL tmp= n^digit[i];
28         if(tmp<n && gcd(n,tmp)==digit[i])   ans[c++]= tmp;
29     }
30     sort(ans,ans+c);
31     printf("%d\n",c);
32     for(int i=0; i<c-1; ++i)
33         printf("%I64d ",ans[i]);
34     if(c)   printf("%I64d\n",ans[c-1]);
35     else    puts("");
36 }
37
38 int main()
39 {
40     int k=0;
41     LL n;
42     while(~scanf("%I64d",&n)){
43         printf("Case #%d:\n",++k);
44         solve(n);
45     }
46     return 0;
47 }

  情人节,唉~也算是收到了意料之外的礼物,具体就不说了~~

BestCoder Valentine's Day Round

时间: 2024-11-05 04:52:11

BestCoder Valentine's Day Round的相关文章

Valentine&#39;s Day Round hdu 5176 The Experience of Love [好题 带权并查集 unsigned long long]

传送门 The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 91 Problem Description A girl named Gorwin and a boy named Vivin is a couple. They arriv

Valentine&#39;s Day Round 1002 Misaki&#39;s Kiss again

题意 Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 571    Accepted Submission(s): 75 问题描述 摩天轮后,一些朋友希望再次得到Misaki的吻,所以Misaki把他们分别编号从1到N,如果他们中有人的编号是M,而且gcd(N,M)=N xor M,那么他以可以得

Valentine&#39;s Day Round 1001.Ferries Wheel(hdu 5174)解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1]<A[i]<A[i+1](1<i<K).现在要求的是,有多少人满足,(他坐的缆车的值 + 他左边缆车的值) % INT_MAX == 他右边缆车的值. 首先好感谢出题者的样例三,否则真的会坑下不少人.即同一部缆车可以坐多个人.由于缆车的值是唯一的,所以可以通过排序先排出缆车的位置.求出

&#183;BC」 Round 3

1.HDU 4097 - Task schedule ( Hash+倒序处理 or 并查集 ) 输入的第一行包含一个整数T, 表示一共有T组测试数据. 对于每组测试数据: 第一行是两个数字n, m,表示工作表里面有n个任务, 有m个询问: 第二行是n个不同的数字t1, t2, t3....tn,表示机器在ti时间执行第i个任务. 接下来m行,每一行有一个数字q,表示在q时间有一个工作表之外的任务请求. 特别提醒:m个询问之间是无关的. #include <cstdio> #include &l

HDU 5175 Misaki&#39;s Kiss again (异或运算,公式变形)

Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 201    Accepted Submission(s): 57 Problem Description After the Ferries Wheel, many friends hope to receive the Misaki's kiss

HDU 5176 The Experience of Love (带权并查集 + 贪心)

The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 275    Accepted Submission(s): 111 Problem Description A girl named Gorwin and a boy named Vivin is a couple. They arrived

BestCoder Round #91

传送门:http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2391&source=1&searchmode=source A题:给你n种字母,每种字母有个权值vali,共cnti个,现在让你在里面挑出任意数量的字符,组合成一个字符串,该字符串的权值的计算方式为val1*1+val2*2+--+valn*n,让你输出字符串最大的权值是多少.这题很容易会有一个错误的贪心,就是把val为负的舍去,然后v

BestCoder Round #65 (ZYB&#39;s Game)

ZYB's Game Accepts: 672 Submissions: 1207 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description ZYBZYBZYB played a game named NumberBombNumber BombNumberBomb with his classmates in hiking:a host keeps a

hdu5418 BestCoder Round #52 (div.2) Victor and World ( floyd+状压dp)

Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to