我的作用:增加罚时。 noip380分大佬全程带飞出了10T,可惜被我搞的罚时太高了。。。

那啥,你会发现java代码有两种风格,嗯两个人,c++自然就是自招大佬了。。。

A:大水题略

B:(不是我写的。。。而且我还没看,,,对这种题一点兴趣没有

import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
char[] a = sc.next().toCharArray();
int t1[][] = me('P', 'S', 'R', n, a);//r
int t2[][] = me('S', 'R', 'P', n, a);//p
int t3[][] = me('R', 'P', 'S', n, a);//s
int tt1[][] = mee('P', 'S', 'R', n, a);//r
int tt2[][] = mee('S', 'R', 'P', n, a);//p
int tt3[][] = mee('R', 'P', 'S', n, a);//s
long ans = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
int x1, x2, x3;
if (i - 1 >= 0) {
x1 = t1[0][i - 1];
} else {
x1 = 0;
}
if (i <= n - 1) {
if (j - 1 >= 0) {
x2 = t2[i][i + j - 1];
} else {
x2 = 0;
}
} else {
x2 = 0;
}
if (i + j <= n - 1) {
x3 = t3[i + j][n - 1];
} else {
x3 = 0;
} int xx1, xx2, xx3;
if (i - 1 >= 0) {
xx1 = tt1[0][i - 1];
} else {
xx1 = 0;
}
if (i <= n - 1) {
if (j - 1 >= 0) {
xx2 = tt2[i][i + j - 1];
} else {
xx2 = 0;
}
} else {
xx2 = 0;
}
if (i + j <= n - 1) {
xx3 = tt3[i + j][n - 1];
} else {
xx3 = 0;
} if ((x1 + x2 + x3) < (xx1 + xx2 + xx3)) {
ans++;
}
}
} System.out.println(ans); }
} static int[][] me(char a, char b, char c, int n, char[] aa) {
int t1[][] = new int[n][n];
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = i; j < n; j++) {
if (aa[j] == a) {
cnt++;
}
t1[i][j] = cnt;
}
}
return t1;
} static int[][] mee(char a, char b, char c, int n, char[] aa) {
int t1[][] = new int[n][n];
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = i; j < n; j++) {
if (aa[j] == b) {
cnt++;
}
t1[i][j] = cnt;
}
}
return t1;
} }

C:大水题

import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
char[] s = sc.next().toCharArray();
char[] a = new char[n];
for (int i = 0; i < n; i++) {
if (s[i] == '*') {
a[i] = '*';
if (i - 1 >= 0) {
a[i - 1] = '*';
}
if (i + 1 < n) {
a[i + 1] = '*';
}
}
}
int x = 0;
double ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] != '*') {
x++;
} else {
ans += Math.ceil(x / 3.0);
x = 0;
}
}
ans += Math.ceil(x / 3.0);
System.out.println((int)ans);
}
}
}

D:有官方题解,还是比较好懂的,这个是我照着题解写的。。。

注意dp指的是区间的个数,所以最后要减1.

#include <bits/stdc++.h>
using namespace std; int t;
char s[100005];
int dp[100005];//分区
int main(){
scanf("%d",&t);
int l,k;
while (t--){
scanf("%d%d",&l,&k);
scanf("%s",&s);
memset(dp,0, sizeof(dp));
dp[l]=0;
for(int i = l-1;i>=0;--i){
bool isAlter = true;
dp[i] = 1e9;
for(int j=i;j-i+1<=k&&j<l;j++){
if (j>i&&s[j]==s[j-1]){
isAlter = false;
}
if (i==j||!isAlter){
dp[i] = min(dp[i],1+dp[j+1]);
}
}
}
printf("%d\n",dp[0]-1);
}
}

E:大水题

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer; public class Main {
static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tok;
static boolean hasNext()
{
while(tok==null||!tok.hasMoreTokens())
try{
tok=new StringTokenizer(in.readLine());
}
catch(Exception e){
return false;
}
return true;
}
static String next()
{
hasNext();
return tok.nextToken();
}
static long nextLong()
{
return Long.parseLong(next());
}
static int nextInt()
{
return Integer.parseInt(next());
}
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) {
int t = nextInt();
while (t--!=0){
int n = nextInt();
int a[] = new int[n];
int max = 0;
for(int i=0;i<n;i++) {
a[i] = nextInt();
max = a[i] > max ? a[i] : max;
}
int temp = 100-max;
int num = 0;
for(int i=0;i<n;i++){
if (a[i]+temp>=50){
num++;
}
}
out.println(num);
}
out.flush();
}
}

F:最小生成树板子题。(归排很辣眼睛,队友说java自带的排序就很好,nlogn,好像还真是。。。可是又有人说那是n方的,,我很迷茫

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer; public class Main {//最小生成树
static int n;//点的个数
static int m;//无向边的个数
static Graph graph[]; static int fa[];
static int rank[]; static int ans;
public static void main(String args []) {
int t = nextInt();
while (t--!=0){
n = nextInt();
m = nextInt();
if (m==0){
out.println("0");
out.flush();
continue;
}
fa = new int[100010];
rank = new int[100010];
for (int i=1;i<=100000;i++){
fa[i]=i;
rank[i]=0;
}
ans = 0;
graph = new Graph[m];
for (int p=0;p<m;p++){
int st = nextInt();
int end = nextInt();
int w = nextInt();
graph[p] = new Graph(st,end,w);
}
graph = mergeSort(graph);
int i=0;
int num=0;
while (num<n-1){
if (same(graph[i].st,graph[i].end)){//在一起
i++;
}
else {
unite(graph[i].st,graph[i].end);
num++;
ans=ans>graph[i].w?ans:graph[i].w;
}
}
out.println(ans);
out.flush();
}
} public static int find(int a){
if (a==fa[a]){
return a;
}
else {
return fa[a] = find(fa[a]);
}
} public static void unite(int x,int y){
x = find(x);
y = find(y);
if (x==y)return;
if (rank[x]<rank[y]){
fa[x] = y;
}else {
fa[y]=x;
if (rank[x]==rank[y]) rank[x]++;
}
} public static boolean same(int x,int y){
return find(x)==find(y);
} public static Graph [] mergeSort(Graph a[]) {
return merge(a,0,a.length-1);
}
public static Graph [] merge(Graph a[],int start,int end) {
int mid = (start+end)/2;
if(start==end)
return new Graph[] {a[start]};
else {
return guibing(merge(a,start,mid),merge(a,mid+1,end));
}
}
public static Graph [] guibing(Graph a[],Graph b[]){
int n = a.length+b.length;
Graph c[] = new Graph[n];
int i=0;int j=0;int s = 0;
while(i<a.length&&j<b.length){
if(a[i].w<b[j].w){
c[s++]=a[i++];
}
if(i<a.length&&a[i].w>b[j].w){
c[s++]=b[j++];
}
if(j<b.length&&i<a.length&&a[i].w==b[j].w) {
c[s++]=a[i++];
c[s++]=b[j++];
}
}
while(i<a.length)
c[s++]=a[i++];
while(j<b.length)
c[s++]=b[j++];
return c;
} static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tok;
static boolean hasNext()
{
while(tok==null||!tok.hasMoreTokens())
try{
tok=new StringTokenizer(in.readLine());
}
catch(Exception e){
return false;
}
return true;
}
static String next()
{
hasNext();
return tok.nextToken();
}
static long nextLong()
{
return Long.parseLong(next());
}
static int nextInt()
{
return Integer.parseInt(next());
}
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); static class Graph {
int st;
int end;
int w; public Graph(int a, int b, int c) {
st = a;
end = b;
w = c;
}
}
}

G:我是傻逼! 我非要贪心wa了三发。。。我是傻逼!!!直接搜就完事了。。。(顺便问下问啥不能贪心啊,求前缀和,然后再求能扔出去几个,257第一遍搜了三个,第二遍把2扔出去)(我跟大佬说了题意然后一瞬间写完了。。。)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int T,n,s,a[],ans;
int cmp(int x,int y){
return x>y;
}
void Dfs(int now,int sum,int cnt){
if(sum>=s){
ans=max(ans,cnt);return;
}
if(now==n+){
if(sum>=s)ans=max(ans,cnt);
return;
}
Dfs(now+,sum+a[now],cnt+);
Dfs(now+,sum,cnt);
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&s);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n,cmp);
ans=;Dfs(,,);
printf("%d\n",ans);
}
return ;
}

H:我没看,tarjan缩点好像是?就最近codeforce有一场contest有一道题就是tarjan缩点,不妨自己找一下(我只想快点回宿舍洗澡)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#define maxn 200010
using namespace std;
int T,n,m,num,head[maxn],dfn[maxn],low[maxn];
int s[maxn],top,f[maxn],topt,bl[maxn];
int Head[maxn],N;
queue<int>q;
struct node{
int v,pre;
}e[maxn],p[maxn];
int init(){
int x=,f=;char s=getchar();
while(s<''||s>''){if(s=='-')f=-;s=getchar();}
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x*f;
}
void Memset(){
memset(head,,sizeof(head));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(s,,sizeof(s));
memset(f,,sizeof(f));
memset(bl,,sizeof(bl));
memset(Head,,sizeof(Head));
N=;num=;top=;topt=;N=;
}
void Add(int from,int to){
num++;e[num].v=to;
e[num].pre=head[from];
head[from]=num;
}
void Ad(int from,int to){
num++;p[num].v=to;
p[num].pre=Head[from];
Head[from]=num;
}
void Tarjan(int u,int from){
dfn[u]=low[u]=++topt;
s[++top]=u;f[u]=;
for(int i=head[u];i;i=e[i].pre){
int v=e[i].v;
if(v==from)continue;
if(dfn[v]==){
Tarjan(v,u);low[u]=min(low[u],low[v]);
}
else if(f[v])low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
N++;while(s[top]!=u){
f[s[top]]=;bl[s[top]]=N;top--;
}
f[s[top]]=;bl[s[top]]=N;top--;
}
}
int Bfs(int S){
memset(f,,sizeof(f));
memset(s,,sizeof(s));
f[S]=;q.push(S);
while(!q.empty()){
int k=q.front();q.pop();
for(int i=Head[k];i;i=p[i].pre){
int v=p[i].v;
if(f[v])continue;
f[v]=;q.push(v);s[v]=s[k]+;
}
}
int mx=,V=S;
for(int i=;i<=N;i++)
if(mx<s[i]){
mx=s[i];V=i;
}
return V;
}
int Bf(int S){
memset(f,,sizeof(f));
memset(s,,sizeof(s));
f[S]=;q.push(S);
while(!q.empty()){
int k=q.front();q.pop();
for(int i=Head[k];i;i=p[i].pre){
int v=p[i].v;
if(f[v])continue;
f[v]=;q.push(v);s[v]=s[k]+;
}
}
int mx=;
for(int i=;i<=N;i++)
mx=max(mx,s[i]);
return mx;
}
int main(){
T=init();
while(T--){
n=init();m=init();int u,v;
Memset();
for(int i=;i<=m;i++){
u=init();v=init();
Add(u,v);Add(v,u);
}
for(int i=;i<=n;i++)
if(dfn[i]==)Tarjan(i,);
num=;for(u=;u<=n;u++)
for(int i=head[u];i;i=e[i].pre){
v=e[i].v;
if(bl[u]==bl[v])continue;
Ad(bl[u],bl[v]);
}
int S=Bfs();
printf("%d\n",num/-Bf(S));
}
return ;
}

I: 和  挑战程序设计 上一道农夫挤牛奶(区间反转)很像,关键是优化的思想!!(我说我的队友一直在看那本书。。。)优化真的挺难懂。

#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
int num[];
char s[];
int t;
int main(){
scanf("%d",&t);
while (t--){
scanf("%s",s);
int n = strlen(s);
for(int i=;i<n;i++){
num[i] = s[i]-'';
}
int ans ;
for(ans = n;ans>=;ans--){//枚举区间
int flag;
for(int k=;k<;k++){//枚举要变成的值
int sum = ,change[]={};
for(int i=;i<n-(ans-);i++){//后面的转不了
if(i-ans>=){
sum-=change[i-ans];
}
change[i]=((k+)-(num[i]+sum)%)%;
sum+=change[i];
}
flag=;
for(int i=n-(ans-);i<n;i++){
if(i-ans>=){
sum-=change[i-ans];
}
change[i]=((k+)-(num[i]+sum)%)%;
if(change[i]!=){
flag = ;
break;
}
}
if (flag){
printf("%d\n",ans);
break;
}
}
if (flag)
break;
}
}
return ;
}

J:这个题我wa了,很玄学,然后我的队友用我的思路写了一发ac了。。。

import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
int k =sc.nextInt();
int a [] = new int[99];
int b [] = new int[99];
for(int i = 0 ; i < n ; i ++){
a[sc.nextInt()]++;
}
for(int i = 0 ; i < k ; i ++){
b[sc.nextInt()]++;
}
int j=0;
for(int i = 0 ; i <20;i++){
if(a[i]>0) {
j++;
for (; j < 60; j++) {
if(b[j]>=a[i]){
break;
}
}
}
}
System.out.println(j>52?"NO":"YES");
}
}
}
class A{
boolean f;
int n;
}

K;没看,好像是个水题?

import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
int k =sc.nextInt();
int a[] = new int[n];
int b[] = new int[100010];
for(int i = 0 ; i< n;i++){
int t = sc.nextInt();
b[t]++;
}
boolean yes= false;
for(int i = 1 ; i <= k;i++){
if(b[i]>0&&k%i==0){
if((b[k/i])>0){
if(k/i==i&&b[i]<=1){
continue;
}
System.out.println(i+" "+k/i);
yes=true;
break;
}
}
}
if(!yes){
System.out.println(-1);
}
}
}
}

L:

都到K题了你还不满足???你个贪得无厌的男人!树上dp是不可能碰的,数据结构啥的都不会,dp啥的也都不会,那岂不是负负得正!!!

这次随机大乱斗体验还不错,队友都太强了,希望以后可以多抱大腿,同时也提醒了我 书 的重要性。  溜了溜了(今天还没正式开始以后就9点到10点全在实验室了。。。)

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>usingnamespacestd; int T,n,s,a[11],ans; int cmp(int x,int y){ return x>y; } void Dfs(int now,int sum,int cnt){ if(sum>=s){ ans=max(ans,cnt);return; } if(now==n+1){ if(sum>=s)ans=max(ans,cnt); return; } Dfs(now+1,sum+a[now],cnt+1); Dfs(now+1,sum,cnt); } int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&n,&s); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n,cmp); ans=0;Dfs(1,0,0); printf("%d\n",ans); } return0; }

Gym 100712的更多相关文章

  1. Gym 100712I Bahosain and Digits(开关翻转问题)

    http://codeforces.com/gym/100712/attachments 题意: 给出一串数字,每次选择连续的k个数字加上任意数(超过10就取余),最后要使得所有数字都相等,求最大的k ...

  2. Gym - 100712D Alternating Strings

    http://codeforces.com/gym/100712/attachments 题意: 给出一个01串,现在要切割这个01串,使得每个子串长度都不大于k,并且每个子串不能01交替出现,单个字 ...

  3. Bridges Gym - 100712H  无向图的边双连通分量,Tarjan缩点

    http://codeforces.com/gym/100712/attachments 题意是给定一个无向图,要求添加一条边,使得最后剩下的桥的数量最小. 注意到在环中加边是无意义的. 那么先把环都 ...

  4. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  5. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  6. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  7. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  8. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  9. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

随机推荐

  1. jQuery插件备忘

    jQuery BlockUI Plugin  遮罩插件                                                                          ...

  2. Go语言字典树定义及实现

    // trie 字典树实现 package Algorithm // 字典树节点 type TrieNode struct { children map[interface{}]*TrieNode i ...

  3. mybatis 批量添加

    <insert id="addTrackBatch" parameterType="java.util.List"> INSERT INTO t_t ...

  4. MyBatis架构与源码分析<资料收集>

    1.架构与源码分析 :https://www.cnblogs.com/luoxn28/p/6417892.html .https://www.cnblogs.com/wangdaijun/p/5296 ...

  5. 什么?又是404!趣图助你理解HTTP状态码~

    HTTP状态码(一):   注释: 301—永久移动.被请求的资源已被永久移动位置: 302—请求的资源现在临时从不同的 URI 响应请求: 305—使用代理.被请求的资源必须通过指定的代理才能被访问 ...

  6. WPF模拟键盘输入和删除

    private void ButtonNumber_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; str ...

  7. A Sample Linker Script

    from:http://www.hertaville.com/a-sample-linker-script.html A sample script file that will work with ...

  8. Mac NVM 配置

    1.NVM 简介 NVM(node version manager)是一个可以让你在同一台机器上安装和切换不同版本 node 的工具. GitHub 地址 2.NVM 环境配置 2.1 安装 NVM ...

  9. Android studio Program type already present: com.****.BuildConfig

    Android studio 抛错,是因为有2个module在 AndroidManifest.xml 里面具有一样的package name,修改不同名字即可. 还有一种情况是多个module对同一 ...

  10. 物联网全景动态图谱2.0|PaaS物联网平台汇总(上篇)

    物联网智库 原创 物联网智库 整理发布 转载请注明来源和出处 ------   [导读]   ------ 毫无疑问,2018年物联网对行业的深度变革才刚刚开启. 物联网产业链企业的质与量将进入全面爆 ...