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

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

 #include<cstdio>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const int INF= 0x7fffffff; typedef map<int,int>::iterator mit; mit operator +(const mit &p, int i)
{
mit it= p;
return ++it;
} mit operator -(const mit &p, int i)
{
mit it= p;
return --it;
} int main(){
int n,i,x,k= ;
map<int,int> m;
while(~scanf("%d",&n)){
m.clear();
for(i=; i<=n; ++i){
cin>>x;
if(m.find(x)!=m.end()) ++m[x];
else m.insert(pair<int,int>(x,));
}
if(m.size()==) {
printf("Case #%d: -1\n",++k);
continue;
}
mit st= m.begin(), it= st, ed= m.end()-; int ans= ;
for(++it; it!=ed; ++it)
if(((LL)it->first+ (it-)->first)%INF == (it+)->first) ans+= it->second; if(((LL)st->first+ ed->first)%INF== (st+)->first) ans+= st->second;
if(((ed-)->first+ (LL)ed->first)%INF== st->first) ans+= ed->second;
printf("Case #%d: %d\n",++k,ans);
}
return ;
}

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

 #include <stdio.h>
#include <string.h>
#include <map>
#include <algorithm>
#define INT_MAX 2147483647
using namespace std; int main()
{
int n, k = ;
long long ans;
long long a[];
while(~scanf("%d", &n))
{
ans = ;
map<int, int> mm;
int cnt = , tmp;
for(int i = ; i < n; i++)
{
scanf("%d", &tmp);
if(!mm[tmp])
{
a[cnt++] = tmp;
}
mm[tmp]++;
}
if(cnt == )
{
printf("Case #%d: -1\n", k++);
continue;
}
sort(a, a+cnt);
for(int i = ; i < cnt; i++)
{
if((a[(i - + cnt) % cnt] + a[(i - + cnt) % cnt]) % INT_MAX == a[i])
{
ans += mm[a[(i - + cnt) % cnt]];
}
}
printf("Case #%d: %d\n", k++, ans);
}
return ;
}

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

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL; LL gcd(LL a, LL b) { return b==? a: gcd(b,a%b); } LL digit[]= {}, ans[]; void solve(LL n)
{
if(n==){
puts("0\n");
return;
}
int num= ;
LL m= sqrt(n+0.5);
for(LL i=; i<=m; ++i)
if(n%i==){
digit[++num]= i;
if(n/i!=i) digit[++num]= n/i;
}
int c= ;
for(int i=; i<=num; ++i){
LL tmp= n^digit[i];
if(tmp<n && gcd(n,tmp)==digit[i]) ans[c++]= tmp;
}
sort(ans,ans+c);
printf("%d\n",c);
for(int i=; i<c-; ++i)
printf("%I64d ",ans[i]);
if(c) printf("%I64d\n",ans[c-]);
else puts("");
} int main()
{
int k=;
LL n;
while(~scanf("%I64d",&n)){
printf("Case #%d:\n",++k);
solve(n);
}
return ;
}

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

BestCoder Valentine's Day Round的更多相关文章

  1. Valentine'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 (Ja ...

  2. Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1] ...

  3. hdu 5175(数论)

    Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  4. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  5. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  6. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  7. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  8. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  9. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

随机推荐

  1. android中文件操作的四种枚举

    1.MODE_PRIVATE:默认操作模式,代表该文件是私有数据,只能被应用自身访问,在该模式下,写入的的内容会覆盖原文件中的内容. 2.MODE_APPEND:该模式会检查文件是否存在,存在就往文件 ...

  2. Paths on a Grid(简单组合数学)

    Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...

  3. Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)

    http://blog.csdn.net/menglei8625/article/details/7494094

  4. Entity Framework 第二篇 事务

    Entity Framework  事务 结合第一篇的代码 public class BaseRepository : ITransaction, IDisposable { private XFDb ...

  5. ByteBuffer解析

    一.前言 前一篇文章我们介绍了Android中直播视频技术的基础大纲知识,这里就开始一一讲解各个知识点,首先主要来看一下视频直播中的一个重要的基础核心类:ByteBuffer,这个类看上去都知道了,是 ...

  6. DBCP连接Oracle,数据库重启后现OALL8 is in an inconsistent state异常

    最近,DBCP连接Oracle,数据库重启后现OALL8 is in an inconsistent state异常. 版本说明 commons-dbcp-1.4.jar commons-pool-1 ...

  7. 有关Duilib的博客(持续更新)

    1.转载:http://blog.csdn.net/LostSpeed/article/category/1896505 2.支持多线程和动画 转载:http://blog.csdn.net/Skil ...

  8. Linux网络统计工具/命令

    我在Linux(基于CentOS 或者 Debian 的发行版)中该如何查看当前网络端口吞吐量的统计信息?在Linux操作系统中如何查看当前内核snmp计数器以及网络端口的统计信息? 你可以使用以下任 ...

  9. Response.Cookies 和 Request.Cookies

    Response.Cookies 和 Request.Cookies     原文地址: http://www.cnblogs.com/forcertain/archive/2012/12/04/28 ...

  10. shell 随机从文件中抽取若干行

    shuf -n5 main.txt sort -R main.txt | head -5 awk -vN=5 -vC="`wc -l file`" 'BEGIN{srand();w ...