题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768

题意:有n个社团发传单,每个社团发给编号为A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i, A_i+(k+1)*C_i>B_i)的学生,求收到传单数为奇数的学生的编号和收到的传单数,题目保证最终最多只有一个为奇数。

分析:x^x=0,x^0=x,因为最终最多只有一个奇数,所以如果存在奇数的话,当所有数异或完之后的值为该奇数,如果不存在的话,异或完后值为0。然后再重头扫一遍计数就行了。

网上那个二分的方法代码还是看不懂=_=...

AC代码:

 #include<stdio.h>
int a[],b[],c[];
int main()
{
int n,i,ans,j,cnt;
while(scanf("%d",&n)!=EOF)
{
cnt=;
ans=;
for(i=;i<n;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
for(j=a[i];j<=b[i];j+=c[i])
ans^=j;
}
for(i=;i<n;i++)
{
for(j=a[i];j<=b[i];j+=c[i])
if(ans==j)
cnt++;
}
if(cnt)
printf("%d %d\n",ans,cnt);
else
printf("DC Qiang is unhappy.\n");
}
return ;
}

最新文章

  1. SharePoint 2013 Search REST API 使用示例
  2. Python之路 day2 按行读文件
  3. php 数据库select函数//待编辑
  4. Dripicons – 精美的扁平风格的免费矢量图标字体
  5. DirectX API 编程起步 #01 项目设置
  6. static cross compile gtk-2.16.6+gtk-directfb+arm-linux (arm-linux-gcc-3.4.4+glib-2.3.5)
  7. android开发文档工具集(持续更新中...)
  8. win7 下配置Openssl
  9. [转]Oracle分页之二:自定义web分页控件的封装
  10. yum 安装 依赖报错
  11. No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)
  12. 使用Heartbeat实现双机热备
  13. 前端工具 - 15个最佳的 JavaScript 表单验证库
  14. .NET: 谈谈共享项目 (Shared Project) 的使用
  15. android的消息通知栏
  16. Hbase数据库
  17. kafka清理数据日志
  18. 一个封装不错的 TcpClient 类
  19. Zip伪加密 破解ZIP密码
  20. 如何用Procmon.exe来监视SQLSERVER的logwrite大小

热门文章

  1. 向大家推荐一个在.Net下使用C#语言和Managed DirectX 9开发游戏的视频教程
  2. 各种 mv power cell
  3. Python2.7-codecs
  4. CSS grid layout
  5. jqgrid 编辑行、新增行、删除行、保存行
  6. js中常见继承方式
  7. [Oracle]查看数据是否被移入 DataBuffer 的方法
  8. mfc Radio Buttons
  9. CF434D Nanami&#39;s Power Plant
  10. [SHELL]输入输出重定向与管道