2013长春网赛1010 hdu 4768 Flyer
2024-08-25 09:12:02
题目链接: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 ;
}
最新文章
- SharePoint 2013 Search REST API 使用示例
- Python之路 day2 按行读文件
- php 数据库select函数//待编辑
- Dripicons – 精美的扁平风格的免费矢量图标字体
- DirectX API 编程起步 #01 项目设置
- static cross compile gtk-2.16.6+gtk-directfb+arm-linux (arm-linux-gcc-3.4.4+glib-2.3.5)
- android开发文档工具集(持续更新中...)
- win7 下配置Openssl
- [转]Oracle分页之二:自定义web分页控件的封装
- yum 安装 依赖报错
- 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)
- 使用Heartbeat实现双机热备
- 前端工具 - 15个最佳的 JavaScript 表单验证库
- .NET: 谈谈共享项目 (Shared Project) 的使用
- android的消息通知栏
- Hbase数据库
- kafka清理数据日志
- 一个封装不错的 TcpClient 类
- Zip伪加密 破解ZIP密码
- 如何用Procmon.exe来监视SQLSERVER的logwrite大小