Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
2015-07-23 18:06
585 查看
思路:由于hit的时间涉及浮点数,处理起来较繁琐,所以可以换一种思路。由于所有的monster同时被attack,所以处理1s内的情况即可。预处理一秒内两个人的hit顺序,若同时hit则记为BOTH。
预处理hit次序只需按次数进行扫描,设当前VANYAhit次数为hit_x,VOVA为hit_y,则VANYA的下一次hit时刻为(hit_x + 1)/x,VOVA的下一次hit时刻为(hit_y + 1)/y
①next_x < next_y,说明最近的hit时刻属于VANYA,则此次攻击记录VANYA,hit_x ++
②next_x > next_y,说明最近的hit时刻属于VOVA,则此次攻击记录VOVA,hit_y ++
③next_x = next_y,说明最近的hit时刻两人同时攻击,这两次攻击都记录BOTH,hit_x ++ hit_y++
一秒内hit总和为x+y,所需时间为O(x+y)
代码如下:
预处理hit次序只需按次数进行扫描,设当前VANYAhit次数为hit_x,VOVA为hit_y,则VANYA的下一次hit时刻为(hit_x + 1)/x,VOVA的下一次hit时刻为(hit_y + 1)/y
①next_x < next_y,说明最近的hit时刻属于VANYA,则此次攻击记录VANYA,hit_x ++
②next_x > next_y,说明最近的hit时刻属于VOVA,则此次攻击记录VOVA,hit_y ++
③next_x = next_y,说明最近的hit时刻两人同时攻击,这两次攻击都记录BOTH,hit_x ++ hit_y++
一秒内hit总和为x+y,所需时间为O(x+y)
代码如下:
#include <cstdio> #include <algorithm> using namespace std; #define N 2000005 #define VANYA 0 #define VOVA 1 #define BOTH 2 int sta , a[100005]; char ans[3][6] = {"Vanya", "Vova", "Both"}; int main(){ int n, x, y; scanf("%d %d %d", &n, &x, &y); for(int i = 0; i < n; ++i) scanf("%d", &a[i]); int hit_x = 0, hit_y = 0, idx = 0, total = x + y; while(hit_x < x && hit_y < y){ double next_x = (double)(hit_x + 1) / x, next_y = (double)(hit_y + 1) / y; if(next_x < next_y) sta[idx] = VANYA, hit_x ++; else if(next_x > next_y) sta[idx] = VOVA, hit_y ++; else sta[idx] = BOTH, sta[++idx] = BOTH, hit_x ++, hit_y ++; ++idx; } for(int i = 0; i < n; ++i){ int last = (a[i] - 1) % total; printf("%s\n", ans[sta[last]]); } return 0; }
相关文章推荐
- ssi开发 学习笔记第三天--配置使用SSI
- Lync2013 for win2008 r2安装心得
- SOA和Web Service
- 泛型的用法
- gradle打包android (实现外部导入签名文件、多渠道打包、导入ant脚本)
- 由LaunchMode引发的问题
- MATLAB与R函数对照(4)——元胞数据与列表、结构体与数据框架函数
- MBProgressHUD -[__NSCFString sizeWithAttributes:]: unrecognized selector问题解决了
- 我眼中的运维
- js trim ie 不兼容
- wireshark怎么抓包、wireshark抓包详细图文教程
- 深入剖析Android音频之AudioTrack
- 图文详解YUV420数据格式
- dedecms织梦建站步骤
- Zxing兼容2.3等低版本
- ios框架
- requireJS
- AngularJS学习笔记(一)
- JSP 2.0 技术书籍 学习笔记
- Mybatis整合Spring