2016ACM/ICPC亚洲区大连站-重现赛
题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016ACM%2FICPC%D1%C7%D6%DE%C7%F8%B4%F3%C1%AC%D5%BE-%D6%D8%CF%D6%C8%FC%A3%A8%B8%D0%D0%BB%B4%F3%C1%AC%BA%A3%CA%C2%B4%F3%D1%A7%A3%A9&source=1&searchmode=source
A.染色乱搞。
- #include <bits/stdc++.h>
- using namespace std;
- typedef struct Edge {
- int to, next;
- }Edge;
- const int maxn = ;
- int n, m, x, y;
- int know[maxn], vis[maxn], color[maxn];
- int ecnt, head[maxn];
- Edge e[maxn*maxn];
- void init() {
- ecnt = ;
- memset(head, -, sizeof(head));
- memset(know, , sizeof(know));
- memset(vis, , sizeof(vis));
- memset(color, , sizeof(color));
- }
- void adde(int u, int v) {
- e[ecnt].to = v, e[ecnt].next = head[u];
- head[u] = ecnt++;
- }
- bool dfs(int u) {
- for(int i = head[u]; ~i; i=e[i].next) {
- int v = e[i].to;
- if(color[v] == color[u]) return ;
- if(vis[v]) continue;
- vis[v] = ;
- color[v] = - color[u];
- if(!dfs(v)) return ;
- }
- return ;
- }
- int main() {
- // freopen("in", "r", stdin);
- int u, v;
- while(~scanf("%d%d%d%d",&n,&m,&x,&y)) {
- init();
- for(int i = ; i < m; i++) {
- scanf("%d%d",&u,&v);
- adde(u, v); adde(v, u);
- know[u] = know[v] = ;
- }
- for(int i = ; i < x; i++) {
- scanf("%d", &u);
- color[u] = ; know[u] = ;
- }
- for(int i = ; i < y; i++) {
- scanf("%d", &u);
- color[u] = ; know[u] = ;
- }
- bool flag = ;
- for(int i = ; i <= n; i++) {
- if(!know[i]) {
- flag = ;
- break;
- }
- }
- if(flag) {
- puts("NO");
- continue;
- }
- for(int i = ; i <= n; i++) {
- if(color[i]) {
- vis[i] = ;
- if(!dfs(i)) {
- flag = ;
- break;
- }
- }
- }
- for(int i = ; i <= n; i++) {
- if(!color[i]) {
- vis[i] = ;
- color[i] = ;
- if(!dfs(i)) {
- flag = ;
- break;
- }
- }
- }
- if(!flag) puts("YES");
- else puts("NO");
- }
- return ;
- }
A
C.威佐夫博弈+大数,根号5用mathmatica跑出来的,其实可以用二分打表。
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.math.MathContext;
- import java.math.RoundingMode;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- BigDecimal n, m;
- BigDecimal sqrt5 = new BigDecimal("2.2360679774997896964091736687312762354406183596115257242708972454105209256378048994144144083787822749695081761507737835");
- while(in.hasNextBigDecimal()) {
- n = in.nextBigDecimal(); m = in.nextBigDecimal();
- if(m.equals(n.max(m))) {
- BigDecimal x = n;
- n = m;
- m = x;
- }
- BigDecimal k = n.subtract(m);
- BigDecimal p = new BigDecimal(1);
- n = p.add(sqrt5).multiply(k);
- n = n.divide(new BigDecimal(2));
- if(n.toBigInteger().equals(m.toBigInteger())) System.out.println("0");
- else System.out.println("1");
- }
- }
- }
C
二分打sqrt(5)
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.math.MathContext;
- import java.math.RoundingMode;
- import java.util.Scanner;
- public class Main {
- public static BigDecimal Get(BigDecimal x) {
- BigDecimal lo = new BigDecimal("0.000000000000000000000000000001");
- BigDecimal hi = x;
- for(int i = 0; i < 1000; i++) {
- BigDecimal mid = lo.add(hi).divide(new BigDecimal("2.0"));
- BigDecimal mid2 = mid.multiply(mid);
- if(mid2.max(x).equals(mid2)) hi = mid;
- else lo = mid;
- }
- return hi;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- BigDecimal n, m;
- BigDecimal sqrt5 = Get(new BigDecimal(5));
- while(in.hasNextBigDecimal()) {
- n = in.nextBigDecimal(); m = in.nextBigDecimal();
- if(m.equals(n.max(m))) {
- BigDecimal x = n;
- n = m;
- m = x;
- }
- BigDecimal k = n.subtract(m);
- BigDecimal p = new BigDecimal(1);
- n = p.add(sqrt5).multiply(k);
- n = n.divide(new BigDecimal(2));
- if(n.toBigInteger().equals(m.toBigInteger())) System.out.println("0");
- else System.out.println("1");
- }
- }
- }
C
D.找到规律gcd(a,b)=gcd(x,y)以后,就是解方程了。
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- LL a, b, x, y;
- LL gcd(LL x, LL y) {
- return y == ? x : gcd(y, x % y);
- }
- int main() {
- // freopen("in", "r", stdin);
- while(~scanf("%I64d%I64d",&a,&b)) {
- LL g = gcd(a, b);
- LL k = b * g;
- if(a * a - * k < || (LL)sqrt(a*a-*k) != sqrt(a*a-*k)) puts("No Solution");
- else {
- LL delta = (LL)sqrt(a * a - * k);
- printf("%I64d %I64d\n", (a-delta)/, (a+delta)/);
- }
- }
- return ;
- }
D
F.考虑让整个数列a最长,那么就是公差为1的等差数列,这时候一定会有不够或者超过x的情况。这时候就把多余的部分从后往前+1补齐。问题就变成在这样一个数列里找到最长的不大于x的个数。由于有取模,所以除法用逆元来做。
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- LL exgcd(LL a, LL b, LL &x, LL &y) {
- if(b == ) {
- x = ;
- y = ;
- return a;
- }
- else {
- LL ret = exgcd(b, a%b, x, y);
- LL tmp = x;
- x = y;
- y = tmp - a / b * y;
- return ret;
- }
- }
- LL inv(LL a, LL m) {
- LL x, y;
- exgcd(a, m, x, y);
- return (x % m + m) % m;
- }
- const LL mod = (LL)1e9+;
- const int maxn = ;
- LL f[maxn];
- int x;
- void init() {
- memset(f, , sizeof(f));
- f[] = ; f[] = ;
- for(int i = ; i < maxn; i++) {
- f[i] = (f[i-] * i) % mod;
- }
- }
- int main() {
- // freopen("in", "r", stdin);
- init();
- int T;
- scanf("%d", &T);
- while(T--) {
- scanf("%d", &x);
- if(x <= ) {
- printf("%d\n", x);
- continue;
- }
- int lo = , hi = maxn;
- int pos = ;
- while(lo <= hi) {
- int mid = (lo + hi) >> ;
- LL s = (mid + ) * (mid - ) / ;
- if(s <= x) {
- lo = mid + ;
- pos = max(pos, mid);
- }
- else hi = mid - ;
- }
- x -= (pos + ) * (pos - ) / ;
- if(x == pos) printf("%I64d\n", (f[pos]*inv(,mod))%mod*(pos+)%mod);
- else if(pos == ) printf("%I64d\n", f[pos]);
- else printf("%I64d\n", f[pos+]*inv(pos-x+,mod)%mod);
- }
- return ;
- }
F
H.奇数就无所谓,偶数的话先手有优势。
- #include <bits/stdc++.h>
- using namespace std;
- int k;
- int main() {
- // freopen("in", "r", stdin);
- while(~scanf("%d", &k)) {
- if(k & ) puts("");
- else puts("");
- }
- return ;
- }
H
I.余弦定理求出第三条边,高用角的一半的余弦乘一下斜边,面积加起来。
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = ;
- const double pi = 3.141592653;
- int n, d;
- int th;
- double ret;
- double f(int th) {
- return d*cos(pi*th/2.0/180.0)*sqrt(2.0*d*d-2.0*d*d*cos(pi*th/180.0))/2.0;
- }
- int main() {
- // freopen("in", "r", stdin);
- while(~scanf("%d%d",&n,&d)) {
- ret = 0.0;
- for(int i = ; i <= n; i++) {
- scanf("%d", &th);
- ret += f(th);
- }
- printf("%.3lf\n", ret);
- }
- return ;
- }
I
J.拆成四部分挨个看看是不是97。
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = ;
- int n;
- int a;
- int f(int x) {
- int cnt = ;
- int q = ;
- while(q--) {
- if((x % ) == ) cnt++;
- x >>= ;
- }
- return cnt;
- }
- int main() {
- // freopen("in", "r", stdin);
- while(~scanf("%d", &n)) {
- int ret = ;
- for(int i = ; i <= n; i++) {
- scanf("%d", &a);
- ret += f(a);
- }
- printf("%d\n", ret);
- }
- return ;
- }
J
2016ACM/ICPC亚洲区大连站-重现赛的更多相关文章
- 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)(7/10)
1001题意:n个人,给m对敌对关系,X个好人,Y个坏人.现在问你是否每个人都是要么是好人,要么是坏人. 先看看与X,Y个人有联通的人是否有矛盾,没有矛盾的话咋就继续遍历那些不确定的人关系,随便取一个 ...
- 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)
http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛
C.Recursive sequence 求ans(x),ans(1)=a,ans(2)=b,ans(n)=ans(n-2)*2+ans(n-1)+n^4 如果直接就去解...很难,毕竟不是那种可以直 ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)
Detachment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)
Convex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/O ...
随机推荐
- z/os上的tar和gzip(3)
前面两篇文章分别讲过了如何合并并压缩批量文件,如何解压缩并恢复批量文件, 这些问题解决了之后还剩下一个大问题,如何在网络上传输这些压缩过的文件,如果是linux的话非常简单,制定binary,然后ge ...
- hadoop 启动停止命令
1 批量启动与停止 1.1 Start-all.sh # Start all hadoop daemons. Run this on master node. bin=`dirname ...
- 小心C# 5.0 中的await and async模式造成的死锁
平时在使用C# 5.0中的await and async关键字的时候总是没注意,直到今天在调试一个ASP.NET项目时,发现在调用一个声明为async的方法后,程序老是莫名其妙的被卡住,就算声明为as ...
- hibernate笔记02
- OpenStack 的NAT解决办法
原因 iptables中的nat表会对数据进行封包换目标,源地址,在我们的系统中是不需要的.所以我们做了如下操作 操作 /etc/nova/nova.conf的 1 2 #routing_source ...
- android 学习随笔二十二(小结)
ADB进程 * adb指令 * adb install xxx.apk * adb uninstall 包名 * adb devices * adb start-server * adb kill-s ...
- virtualbox -centos ping不通外网
centos上配置网卡自动获取ip 在路由器上配置了ip和mac绑定.ping不通外网.删除路由器上的静态mac绑定后OK,不明
- python logging 替代print 输出内容到控制台和重定向到文件
转自:http://blog.csdn.net/z_johnny/article/details/50740528
- 161018、springMVC中普通类获取注解service方法
1.新建一个类SpringBeanFactoryUtils 实现 ApplicationContextAware package com.loiot.baqi.utils; import org.sp ...
- vs2010 仿XCode风格的头注释宏
Sub DocumentFileHeader() Dim star As String star = "//***************************************** ...