BestCoder Valentine's Day Round
昨晚在开赛前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的更多相关文章
- 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 ...
- 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] ...
- hdu 5175(数论)
Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- BestCoder Round #89 02单调队列优化dp
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01 HDU 5944 水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- 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 ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
随机推荐
- c#窗体传志
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- easyui的页面等待提示层,即mask
/* * 使用方法: * 开启:MaskUtil.mask(); * 关闭:MaskUtil.unmask(); * * MaskUtil.mask('其它提示文字...'); */ var Mask ...
- 关于easyui的窗口和tab页面不执行js说明
一直以来群里里面很多人反应,在用tab加载界面的时候,界面里面的js不会执行.今天GodSon在此说明一下原因. 不管是window,dailog还是tab其实质最终都是继承了panel.panel有 ...
- 使用kendoui实现日期除去工作日
<input type="text" id="div-timePrint" value="" readonly="false ...
- c++类中的常量
C++类中的常量 由于#define 定义的宏常量是全局的,不能达到目的,于是想当然地觉得应该用 const 修饰数据成员来实现.const 数据成员的确是存在的,但其含义却不是我们所期望的.cons ...
- 2016年11月19日 星期六 --出埃及记 Exodus 20:10
2016年11月19日 星期六 --出埃及记 Exodus 20:10 but the seventh day is a Sabbath to the LORD your God. On it you ...
- Android超类
android.test.AndroidTestCase android写测试类的超类 android.database.sqlite.SQLiteOpenHelper sqllite的超类
- response.sendRedirect()重新定向的乱码问题
这里response.sendRedirect("YPbianhaoModify.jsp?jinhuoshang="+jinhuoshang+"&jinhuori ...
- 使用jquery构建Metro style 返回顶部
个人一直对metro风格的东西情有独钟,偶然间在腾讯网看到一款小插件,蓝色Metro风格的,所以决定把它放到我的博客中,这样做应该不会有版权问题吧orz.. Complete code 后言 我把他原 ...
- TCP连接的状态详解以及故障排查
我们通过了解 TCP各个状态 ,可以排除和定位网络或系统故障时大有帮助. 一.TCP状态 LISTENING :侦听来自远方的TCP端口的连接请求 . 首先服务端需要打开一个 socket 进行监听, ...