Gym 100712
我的作用:增加罚时。 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的更多相关文章
- Gym 100712I Bahosain and Digits(开关翻转问题)
http://codeforces.com/gym/100712/attachments 题意: 给出一串数字,每次选择连续的k个数字加上任意数(超过10就取余),最后要使得所有数字都相等,求最大的k ...
- Gym - 100712D Alternating Strings
http://codeforces.com/gym/100712/attachments 题意: 给出一个01串,现在要切割这个01串,使得每个子串长度都不大于k,并且每个子串不能01交替出现,单个字 ...
- Bridges Gym - 100712H 无向图的边双连通分量,Tarjan缩点
http://codeforces.com/gym/100712/attachments 题意是给定一个无向图,要求添加一条边,使得最后剩下的桥的数量最小. 注意到在环中加边是无意义的. 那么先把环都 ...
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
随机推荐
- 【linux】linux下准确查询正在tomcat下运行的java进程。准确获取正在运行的java进程的PID
准确获取定位到tomcat下正在运行的java进程的PID命令: ps -ef|grep java | grep catalina | awk '{print $2}' 准确定位到tomcat下正在运 ...
- C# Winform使用Windows Media Player播放多媒体整理
一.简单使用示例步骤 1.添加Windows Media Player 组件当前是系统的 Com组件 工具箱>右键“选择项”>选择Com组件 2.控件拖拽到桌面,使用 private vo ...
- mssql f_Split
mssql可以如下CREATE FUNCTION [dbo].[f_Split] ( @val varchar(max),@Splits varchar(100))RETURNS @Table TAB ...
- 【转】Selenium - 封装WebDrivers (C#)
本文转载自:http://www.cnblogs.com/qixue/p/3977135.html Web element仍然使用OpenQA.Selenium.IWebElement, 本类库将Se ...
- C# Task 是什么?返回值如何实现? Wait如何实现
关于Task的API太多了,网上的实例也很多,现在我们来说说Task究竟是个什么东西[task一般用于多线程,它一定与线程有关],还有它的返回值有事怎么搞的. 首先我们以一个最简单的API开始,Tas ...
- linux下gflags的安装
gflags是google开发的一套命令行参数解析工具,被很多软件系统所依赖,应该算是一个基础的库,安装其实很简单,但是如果在网上找的一些教程大部分都是安装后不能被其他软件调用的,因为默认使用cmak ...
- js-工具函数
/** * 将文件大小转换成 ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],单位 * @param bytes * @returns */ ...
- Guava future
减少主函数的等待时间,使得多任务能够异步非阻塞执行 ListenableFuture是可以监听的Future,它是对java原生Future的扩展增强.Future表示一个异步计算任务,当任务完成时可 ...
- MySQL技术内幕读书笔记(二)——InnoDB存储引擎
目录 InnoDB存储引擎 InnoDB存储架构 Checkpoint技术 Master Thread 工作方式 InnoDB关键特性(放一下,感觉看后面,再看总结吧) InnoDB存储引擎 Inno ...
- Xcode真机调试失败:The identity used to sign the executable is no longer valid
在Xcode中突然好久没有使用真机调试了.今天使用真机的时候.出现例如以下的警告.并真机执行失败: The identity used to sign the executable is no lon ...