前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces Round #503(Div.2)

Codeforces Round #503(Div.2)

作者头像
mathor
发布2018-08-16 16:36:26
4390
发布2018-08-16 16:36:26
举报
文章被收录于专栏:mathormathor
A. New Building for SIS

 签到题,无非就是在同一座塔内和不在同一座塔内分情况考虑

代码语言:javascript
复制
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int h = cin.nextInt();
        int a = cin.nextInt();
        int b = cin.nextInt();
        int k = cin.nextInt();
        for(int i = 0;i < k;i++) {
            int ta = cin.nextInt();
            int fa = cin.nextInt();
            int tb = cin.nextInt();
            int fb = cin.nextInt();
            if(ta == tb)//在一座塔内
                System.out.println(Math.abs(fa - fb));
            else {//不在同一座塔内
                long tmp = Math.abs(ta - tb);
                if(fa <= a && fb <= a) {
                    long tmp1 = Math.abs(fa - a);
                    long tmp2 = Math.abs(fb - a);
                    System.out.println(tmp + tmp1 + tmp2);
                }
                else if(fa >= b && fb >= b) {
                    long tmp1 = Math.abs(fa - b);
                    long tmp2 = Math.abs(fb - b);
                    System.out.println(tmp + tmp1 + tmp2);
                }
                else {
                    long tmp1 = Math.abs(fa - fb);
                    System.out.println(tmp + tmp1);
                }
            }
        }
    }
}
B. Badge

 题意是有n个学生干了一些不可描述的事,然后老师要抓人,当抓到一个学生的时候就给这个学生标记1,然后这个学生会说是另一个学生让他干的,然后老师就会找另一个学生,直到老师找到已经被标记过了两次的学生为止,输出这个学生的编号  也是水题,模拟一下就行了,从1号开始遍历,找到标记两次的,然后清空map,再从2号开始遍历,找到标记两次的,然后清空map,直到到n为止

代码语言:javascript
复制
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int[] stu = new int[n + 1];
        for(int i = 1;i <= n;i++)
            stu[i] = cin.nextInt();
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = 1;i <= n;i++) {
            map.clear();
            int curStu = i;
            while(true) {
                if(!map.containsKey(curStu))
                    map.put(curStu,1);
                else {
                    int times = map.get(curStu);
                    map.put(curStu,++times);
                    if(times == 2) {
                        System.out.print(curStu + " ");
                        break;
                    }
                }
                curStu = stu[curStu];
            }
        }
    }
}
C. Elections
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-08-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A. New Building for SIS
  • B. Badge
  • C. Elections
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档