A:

题意:给定A个N元,B个一元,问是否可以凑成S元。

思路:A*i+j=S 即 A*I<=S<=A*I+B 即min(S/N,A)+B>=S;

/*
@author nimphy
@create 2019-11-05-10:34
about:CF1256A
*/

import java.util.*;

public class CF1256 {
    public static void main(String[] args) {
        Scanner In = new Scanner(System.in);
        int Q, A, B, N, S;
        Q = In.nextInt();
        while (Q-- > 0) {
            A = In.nextInt();
            B = In.nextInt();
            N = In.nextInt();
            S = In.nextInt();
            int I = Math.min(S / N, A) * N;
            //System.out.println(I);
            if (I + B >= S) System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

B:

题意:给定一个排列,现在让你做一套操作,使得字典序最小。

思路:贪心,先尽量把1提到前面,然后是2....,如果满足{位置交换没用过,而且比左边的小就换}

/*
@author nimphy
@create 2019-11-05-11:34
about:CF1256B
*/

import java.util.*;

public class CF1256 {
    static int[] a = new int[1010];
    static boolean[] vis = new boolean[1010];

    public static void main(String[] args) {
        Scanner In = new Scanner(System.in);

        int Q, N;
        Q = In.nextInt();
        while (Q-- > 0) {
            N = In.nextInt();
            for (int i = 1; i <= N; i++) {
                a[i] = In.nextInt();
                vis[i] = false;
            }
            for (int i = 1; i <= N; i++) {
                int pos=0;
                for (int j = 1; j <= N; j++) {
                    if (a[j] == i) {
                        pos = j;
                        break;
                    }
                }
                while (pos > i && !vis[pos]&&a[pos]<a[pos-1]) {
                    int t = a[pos];
                    a[pos] = a[pos - 1];
                    a[pos - 1] = t;
                    vis[pos] = true;
                    pos--;
                }
            }
            for (int i = 1; i <= N; i++) {
                System.out.print(a[i]+" ");
            }
            System.out.println();
        }
    }
}

C:

思路:贪心+情况可能多-----忽略。

------------------------------白嫖了输入优化--------------------------------------

D:

题意: 给定N,K和一个01串,你可以交换相邻的字符,但是次数不超过K次,求最后的最小字典序串。

思路:结论是,把前面的0移动到越前面,字典序最小。 那么我们从前往后扫‘0’,如果前面有x个‘1’,那么它可以和前面第min(x,K)个位置交换。

/*
@author nimphy
@create 2019-11-05-11:34
about:CF1256C
*/

import java.io.*;
import java.util.*;

public class CF1256 {

    private static boolean doLocalTest = System.getSecurityManager() == null;
    private Scanner sc = new Scanner(System.in);
    private PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    public static void main(String[] args) {
        long executionTime = 0;
        if (doLocalTest) {
            executionTime = System.currentTimeMillis();
            try {
                System.setIn((new FileInputStream("in")));
//                System.setOut(new PrintStream(new File("out")));
            } catch (FileNotFoundException e) {
                doLocalTest = false;
            }
        }
        CF1256 cf1256 = new CF1256();
        cf1256.solve();
        if (doLocalTest) {
            cf1256.out.println("======== [ End of Output] ========");
            cf1256.out.println("> Time Spent: " + (System.currentTimeMillis() - executionTime) + " ms");
        }
        cf1256.out.flush();
    }

    static char[] a;
    static char[] ans = new char[10010];

    void solve() {
        int T, N;
        long K;
        T = sc.nextInt();
        while (T-- > 0) {
            N = sc.nextInt();
            K = sc.nextLong();
            a = sc.next().toCharArray();
//            System.out.println(Arrays.toString(a));
            int pre = 0;
            for (int i = 0; i < N && K > 0; i++) {
                if (a[i] == '1') {
                    pre++;
                    continue;
                }
                if (pre == 0) continue;
                int t = pre;
                if (K < t) t = (int) K;
                a[i - t] = '0';
                a[i] = '1';
                K -= t;
            }
            for (int i = 0; i < N; i++) out.print(a[i]);
            out.println();
        }
    }
}

class Scanner {
    private BufferedReader bufferedReader;
    private StringTokenizer stringTokenizer;

    Scanner(InputStream in) {
        bufferedReader = new BufferedReader(new InputStreamReader(in));
        stringTokenizer = new StringTokenizer("");
    }

    String nextLine() {
        try {
            return bufferedReader.readLine();
        } catch (IOException e) {
            throw new IOError(e);
        }
    }

    boolean hasNext() {
        while (!stringTokenizer.hasMoreTokens()) {
            String s = nextLine();
            if (s == null) {
                return false;
            }
            stringTokenizer = new StringTokenizer(s);
        }
        return true;
    }

    String next() {
        hasNext();
        return stringTokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
}

E:

题意:给的大小为N的集合,然后分组,每组元素个数不小于3个,代价是每组的最大值减最小值之和,求分组是的代价最小。

分组越多越好,那么可以假设最多6个一组。    懒得写了,毕竟要输出具体分组。(还不会java的结构体排序)

F:

题意:给定两个字符数组A[] , B[],长度相同。 现在你可以选择可以长度len,然后进行任意轮操作,每轮操作是反转一段A和一段B,其长度都是len,问最后是否可以相同。

思路:发现len选2最优,因为你无论len选多大,都可以由len=2转移过来,达到同样的效果;   那么现在len=2了,又发现,如果某一组有相同的字符,那么另外一组可以任意排列,所以YES;    而如果A和B都是各异的字符,那么如果逆序对的奇偶性相同,则YES。

/*
@author nimphy
@create 2019-11-05-11:34
about:CF1256F
*/

import java.io.*;
import java.util.*;

public class Main {

    private static boolean doLocalTest = System.getSecurityManager() == null;
    private Scanner sc = new Scanner(System.in);
    private PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    public static void main(String[] args) {
        long executionTime = 0;
        if (doLocalTest) {
            executionTime = System.currentTimeMillis();
            try {
                System.setIn((new FileInputStream("in")));
//                System.setOut(new PrintStream(new File("out")));
            } catch (FileNotFoundException e) {
                doLocalTest = false;
            }
        }
        Main fcy = new Main();
        fcy.solve();
        if (doLocalTest) {
            fcy.out.println("======== [ End of Output] ========");
            fcy.out.println("> Time Spent: " + (System.currentTimeMillis() - executionTime) + " ms");
        }
        fcy.out.flush();
    }

    String a,b;
    int[] num1=new int[26];
    int[] num2=new int[26];
    void solve() {
        int T, N;
        long K;
        T = sc.nextInt();
        while (T-- > 0) {
            N = sc.nextInt();
            a=sc.next();
            b=sc.next();
            for(int i=0;i<26;i++) num1[i]=num2[i]=0;
            for(int i=0;i<N;i++) {
                num1[a.charAt(i)-'a']++;
                num2[b.charAt(i)-'a']++;
            }
            boolean Flag=true;
            for(int i=0;i<26;i++) if(num1[i]!=num2[i]) Flag=false;
            if(!Flag) {
                out.println("NO");
                continue;
            }
            for(int i=0;i<26;i++) if(num1[i]>1||num2[i]>1) Flag=false;
            if(!Flag) {
                out.println("YES");
                continue;
            }
            long inv1=0,inv2=0;
            for(int i=0;i<26;i++) num1[i]=num2[i]=0;
            for(int i=0;i<N;i++){
                for(int j=a.charAt(i)-'a'+1;j<26;j++) inv1+=num1[j];
                for(int j=b.charAt(i)-'a'+1;j<26;j++) inv2+=num2[j];
                num1[a.charAt(i)-'a']++;
                num2[b.charAt(i)-'a']++;
            }
            if(Math.abs(inv1-inv2)%2==0) out.println("YES");
            else out.println("NO");
        }
    }
}

class Scanner {
    private BufferedReader bufferedReader;
    private StringTokenizer stringTokenizer;

    Scanner(InputStream in) {
        bufferedReader = new BufferedReader(new InputStreamReader(in));
        stringTokenizer = new StringTokenizer("");
    }

    String nextLine() {
        try {
            return bufferedReader.readLine();
        } catch (IOException e) {
            throw new IOError(e);
        }
    }

    boolean hasNext() {
        while (!stringTokenizer.hasMoreTokens()) {
            String s = nextLine();
            if (s == null) {
                return false;
            }
            stringTokenizer = new StringTokenizer(s);
        }
        return true;
    }

    String next() {
        hasNext();
        return stringTokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
}

CF1256(div3 java题解)的更多相关文章

  1. 【剑指offer】(第 2 版)Java 题解

    [剑指offer](第 2 版)Java 题解 第一章 面试的流程 略... 第二章 面试需要的基础知识 面试题 1. 赋值运算符函数 面试题 2. 实现 Singleton 模式 Solution ...

  2. 试题 历届试题 核桃的数量 java题解

    资源限制 时间限制:1.0s   内存限制:256.0MB 问题描述 小张是软件项目经理,他带领3个开发组.工期紧,今天都在加班呢.为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑).他的要求是: ...

  3. TopCoder SRMS 1 字符串处理问题 Java题解

    Problem Statement   Let's say you have a binary string such as the following: 011100011 One way to e ...

  4. LeetCode108_Convert SortedArray to BinarySearchTree(将有序数组转成二叉排序树) Java题解

    题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...

  5. 7.15实习培训日志 java题解

    周末总结 本周主要学习了markdown,git,docker等工具的使用.在本周的学习中,初步了解了markdown,git,docker的使用.本周的静态博客部署中,对于怎么显示一个博客内容,有两 ...

  6. LeetCode234_PalindromeLinkedList (推断是否为回文链表) Java题解

    题目: Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) ...

  7. L1-027 出租 (20 分) java题解

    下面是新浪微博上曾经很火的一张图: 一时间网上一片求救声,急问这个怎么破.其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对 ...

  8. L1-023 输出GPLT (20 分) java题解 GPLT天梯赛防坑技巧

    上题目先 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区分大小写)的个数不一定是一样多的 ...

  9. 试题 历届试题 翻硬币 java题解

    问题描述 小明正在玩一个"翻硬币"的游戏. 桌上放着排成一排的若干硬币.我们用 * 表示正面,用 o 表示反面(是小写字母,不是零). 比如,可能情形是:**oo***oooo 如 ...

随机推荐

  1. golang 服务端和客户端(二)

    1.golang服务端 package main import( "net/http" ) func main(){ //注册处理函数,用户连接,自动调用指定的处理函数 http. ...

  2. 【目录】洛谷|CODEVS题解汇总

    [动规]爱与愁的心痛 [动规]编辑距离 [动规]采药 [动规]创意吃鱼法 [动规]过河卒 [动规]开心的金明 [动规]旅行 [动规]骑士游历 [动规]数字三角形 [动规]最长连号 [动规]装箱问题 [ ...

  3. 解惑:在Ubuntu18.04.2的idea上运行Scala支持的spark程序遇到的问题

    解惑:在Ubuntu18.04.2的idea上运行Scala支持的spark程序遇到的问题 一.前言 最近在做一点小的实验,用到了Scala,spark这些东西,于是在Linux平台上来完成,结果一个 ...

  4. 在Ubuntu18.04.2LTS上安装视频播放器smplayer/vlc

    在Ubuntu18.04.2LTS上安装视频播放器smplayer/vlc 一.前言 在Ubuntu上的视频播放器质量很差,没有解码器,非常的不方便,于是我们需要手动去安装适合我们的播放器,比如smp ...

  5. c#DateTime与unix时间戳互相转换

    public class UnixTimeUtil { /// <summary> /// 将dateTime格式转换为Unix时间戳 /// </summary> /// & ...

  6. Linux shell自动读mongo数据、远程获取文件大小示例脚本

    1.示例1 功能:对mongoDB导出数据,根据sid的不同状态进行统计 技术点:shell bash  读写文件.字符串截取.函数.用多个文件提到的map.grep查找并赋值给变量 #!/bin/b ...

  7. Beyond Compare的自定义破解方法

    因本人是程序员的缘故,经常时不时就是几千几万行代码找不同,也就时常要用到一个超级无敌好用的文本对比软件:Beyond Compare. 然而破解成了一大问题,网上有很多注册码都已经被封了或者是注销掉了 ...

  8. ICP 匹配定位算法学习记录

    icp 算法原理是: 选取目标点云P和源点云Q,按照一定的约束条件,找到最邻近点(pi,qi),然后计算出最优R和t(旋转和平移), 使得误差函数最小,误差函数E(R,t): 基本算法流程: 1.在目 ...

  9. Theano 报错:No suitable SharedVariable constructor could be found. Are you sure all kwargs are supported? We do not support the parameter dtype or type

    当Theano报错:No suitable SharedVariable constructor could be found. Are you sure all kwargs are support ...

  10. 小记 .NET Core 3.0 下 WPF 是如何运行的

    1. 解决方案架构 如图: 2. 生成的代码 如图: /// <summary> /// App /// </summary> public partial class App ...