省赛组队赛4

C题:http://codeforces.com/problemset/problem/407/A

#include<stdio.h>
#include<math.h>
int main()
{
    int a, b, ax, ay, bx, by;
    while(~scanf("%d%d",&a, &b))
    {
        int flag = 0;
        for(ax = 1; ax < a; ax++) //枚举a的横坐标
        {
            for(bx = 1; bx < b; bx++) //枚举b的横坐标
            {
                ay = (int)sqrt(a*a - ax*ax); //a的纵坐标
                by = (int)sqrt(b*b - bx*bx); //b的纵坐标
                if(ax*ax + ay*ay == a*a && bx*bx + by*by == b*b) //两个都是直角三角形
                {
                    if(ax*bx == ay*by) //两个三角形相似
                    { 
                        if(ax != bx) //保证三角形的边与坐标轴不平行
                        {
                            flag = 1;
                            break;
                        }

                    }
                }
            }
            if(flag)
                break;
        }
        if(!flag)
            printf("NO\n");
        else
        {
            printf("YES\n");
            printf("0 0\n");
            printf("%d %d\n",ax, -ay);
            printf("%d %d\n",bx, by);
        }
    }
    return 0;
}


J题:http://codeforces.com/problemset/problem/405/E

暂时没有彻底弄懂这个题。

#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
struct node
{
    int x, y, z;
    node(int x, int y, int z) : x(x), y(y), z(z) {}
};
vector <int> adj[N];
vector <node> ans;
int vis[N];
int tot;
int dfs(int u, int fa)
{
    vis[u] = ++tot;
    //printf("$-> u = %d, fa = %d, vis[%d] = %d\n",u, fa, u, vis[u]);
    int a = 0;
    int s = adj[u].size();
    for(int i = 0; i < s; i++)
    {
        int v = adj[u][i];
        if(v == fa) continue;
        if(!vis[v])
        {
            if(dfs(v, u))
            {
               // printf("return 1;\n");
                continue;
            }
            if(!a) a = v;
            else
            {
                ans.push_back(node(v, u, a));
           //     printf("****%d %d %d\n",v,u, a);
                a = 0;
            }
        }
        else if(vis[v] < vis[u]) //判断v是不是在u之前出现
        {
            if(!a) a = v;
            else
            {
                ans.push_back(node(v, u, a));
              //  printf("--->%d %d %d\n",v, u, a);
                a = 0;
            }
        }
    }
    if(a)
    {
        ans.push_back(node(a, u, fa));
       // printf("####%d %d %d\n",a, u, fa);
        return 1;
    }
    return 0;
}
int main()
{
    //freopen("a.txt","r",stdin);
    int n, m, u, v, i, j;
    while(~scanf("%d%d",&n,&m))
    {
        memset(vis, 0, sizeof(vis));
        memset(adj, 0, sizeof(adj));
        ans.clear();
        for(i = 0; i < m; i++)
        {
            scanf("%d%d",&u,&v);
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        if(m&1)
        {
            printf("No solution\n");
            continue;
        }
        tot = 0;
        dfs(1, -1);
        int k = ans.size();
        for(i = 0; i < k; i++)
        {
            node tmp = ans[i];
            printf("%d %d %d\n", tmp.x, tmp.y, tmp.z);
        }
        printf("\n");
    }
    return 0;
}
//vis[i]表示第i个点是第几次访问到的

你可能感兴趣的:(省赛组队赛4)