Fighting For 2017 Season Contest 1
比赛地址【https://vjudge.net/contest/147011#problem/A】、960626
题目一:【http://codeforces.com/problemset/problem/701/A】、水题
题意:给出N张纸牌,N为偶数,每张纸牌上有数值,把这N张纸牌分给(N/2)个人,每个人分到两张纸牌,并且数值相同。一定存在解。
法一:
#include<bits/stdc++.h>
using namespace std;
int a[], vis[];
int N;
int main ()
{
int sum = ;
scanf("%d", &N);
for(int i = ; i <= N; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
sum /= N / ;
for(int i = ; i <= N; i++)
{
if(vis[i]) continue;
vis[i] = ;
int t = sum - a[i];
for(int j = i + ; j <= N; j++)
{
if(vis[j]) continue;
if(a[j] == t)
{
printf("%d %d\n", i, j);
vis[j] = ;
break;
}
}
}
return ;
}
法二:
#include<bits/stdc++.h>
using namespace std;
struct node
{
int nu, id;
bool operator <(const node x)const
{
return nu < x.nu;
}
} A[];
int N;
int main ()
{
scanf("%d", &N);
for(int i = ; i <= N; i++)
{
scanf("%d", &A[i].nu);
A[i].id = i;
}
sort(A + , A + N + );
int s = , t = N;
while(s <= t)
{
printf("%d %d\n", A[s].id, A[t].id);
s++, t--;
}
return ;
}
题目二:【https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=614】
题意:
You are given a string consisting of parentheses () and []. A string of this type is said to be correct:
(a) if it is the empty string
(b) if A and B are correct, AB is correct,
(c) if A is correct, (A) and [A] is correct.
Write a program that takes a sequence of strings of this type and check their correctness. Your program can assume that the maximum string length is 128.
题解:虽然长度最长只有128,但是是多组输入,用区间DP会TLE。简单stack的应用。
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF = 1e6;
const int MAXN = ;
char S[MAXN];
int T, N;
int main ()
{
scanf("%d", &T);
getchar();
while(T--)
{
gets(S + );
N = strlen(S + );
if(S[] == ' ')//第一种情况
{
printf("Yes\n");
continue;
}
stack<char>st;
for(int i = ; i <= N; i++)
{
if(!st.empty() && ((st.top() == '(' && S[i] == ')') || (st.top() == '[' && S[i] == ']')))
st.pop();//匹配
else st.push(S[i]);
}
if(st.empty()) printf("Yes\n");
else printf("No\n");
}
return ;
}
题目C:【http://codeforces.com/problemset/problem/382/C】/模拟
题意:给出一列数,使得加入一个数,使他是等差数列。从小到大输出可能的数,如果没有输出0,无限多个-1;
错了好多发。思维;
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ;
map<int, int>mp;
int a[MAXN], N;
int main ()
{
scanf("%d", &N);
for(int i = ; i <= N; i++)
scanf("%d", &a[i]);
sort(a + , a + N + );
if(N == ) printf("-1\n");
else if(N == )
{
if(a[] == a[]) printf("1\n%d\n", a[]);
else
{
int t = a[] + a[];
if(t % )
printf("2\n%d %d\n", * a[] - a[], * a[] - a[]);
else
printf("3\n%d %d %d\n", * a[] - a[], t / , * a[] - a[]);
}
}
else
{
int t1 = -, t2 = -, p1, p2, nu = ;
for(int i = ; i < N; i++)
{
int t = a[i + ] - a[i];
if(mp.count(t)) {mp[t]++;continue;}
nu++;
mp[t] = ;
if(nu == )
t1 = t, p1 = i;
else if(nu == )
t2 = t, p2 = i;
else break;
}
if(nu == )
{
if(t1 == ) printf("1\n%d\n", a[]);
else printf("2\n%d %d\n", a[] - t1, a[N] + t1);
}
else if(nu == )
{
if(t1 > t2)
{
int t = a[p1] + a[p1 + ];
if(t1 != * t2||mp[t1]!=) printf("0\n");
else printf("1\n%d\n", t / );
}
else
{
int t = a[p2] + a[p2 + ];
if(t2 != * t1||mp[t2]!=) printf("0\n");
else printf("1\n%d\n", t / );
}
}
else printf("0\n");
}
return ;
}
题目四:【http://www.spoj.com/problems/INTSUB/en/】快速幂
题意:输入一个数n,有区间【1,2n】找出一个区间,区间中存在数a、b,使得a为区间中最小的数,b为a的整倍数数。
题解:枚举最小的数a,利用组合数公式求出所有的可能的情况,中间用快速幂处理。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + ;
const int mod = ;
int N;
LL fast_mod(int x)
{
LL bas = , ans = ;
while(x)
{
if(x & )
ans = ((ans % mod) * (bas % mod)) % mod;
bas = ((bas % mod) * (bas % mod)) % mod;
x >>= ;
}
return ans % mod;
}
int main ()
{
int T, ic = ;
scanf("%d", &T);
while(T--)
{
scanf("%d", &N);
N <<= ;
LL ans = (fast_mod(N - ) - + mod) % mod;
for(int i = ; i <= N >> ; i++)
{
LL t = N / i - ;
LL x = N - i - t;
ans = (ans + (fast_mod(x) * ((fast_mod(t) - + mod) % mod)) % mod) % mod;
}
printf("Case %d: %lld\n", ++ic, ans); }
return ;
}
题目五:【http://codeforces.com/problemset/problem/607/B】
题意:给出n个数,每次删除一个回文串,求最少的删除次数。
题解:区间DP,dp[l][r],表示区间[l,r]中最少的回文串。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF=1e9;
const int MAXN = ;
int dp[MAXN][MAXN];
int a[MAXN];
int N;
int main ()
{
scanf("%d",&N);
for(int i=;i<=N;i++)
{
scanf("%d",&a[i]);
dp[i][i]=;
}
for(int l=;l<=N;l++)
{
for(int i=;i<=N-l+;i++)
{
int j=i+l-;
dp[i][j]=INF;
if(a[i]==a[j])
{
if(i+==j)
dp[i][j]=dp[i+][j-]+;
else
dp[i][j]=dp[i+][j-];
}
for(int k=i;k<j;k++)
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+][j]);
}
}
printf("%d\n",dp[][N]);
return ;
}
Fighting For 2017 Season Contest 1的更多相关文章
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- IOI 2017 Practice Contest mountains
Mountains 题面 题意: 选最多的点使得两两看不见. 分析: 分治,solve(l,r)为区间[l,r]的答案.那么如果不选最高点,分治两边即可,选了最高点,那么在最高点看不见的区间里分治. ...
- ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...
- HDU-AcmKeHaoWanLe训练实录
菜鸡队训练实录. 现场赛记录:[名称:奖项/排名] 2017: ICPC Shenyang:Gold/3 CCPC Hangzhou:Gold/3 ICPC Beijing:Gold/13 CCPC ...
- hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...
- 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
随机推荐
- oracle 11g使用deferred_segment_creation 延迟段创建特性时遇到的问题总结
总结,下面是两个问题.问题1是用户可以在所有表空间创建表;问题2是exp不能导出空表 问题1: 版本:oracle 11.2.0.1.0 select * from v$version; 创建用户aa ...
- 百度地图在某架构下找不到符号.a文件的问题
1.现象: 就是说找不到符号给i386的架构(就是模拟器).或者找不到符号给arm架构(真机). ld: warning: ignoring file /Users/pufang/xcode/demo ...
- 创建 OVS vlan100 netwrok - 每天5分钟玩转 OpenStack(137)
上一节完成了 OVS vlan network 的配置准备工作,今天我们创建 vlan100.打开菜单 Admin -> Networks,点击 "Create Network&quo ...
- [ios] 微信订阅号: ios博文精选
晚上下班后时间充裕,平时要么看电视剧,要么玩游戏 感觉浪费时间. 最后决定自己也搞一个微信订阅号分享技术方面的东西,也提升自己. 如果大家也是一样情况,欢迎大家关注我的订阅号. 微信订阅号: ios ...
- jsp-2 简单的servlet连接mysql数据库 增删改查
连接mysql数据库的操作 有增删改查 用的包有 commons-lang3-3.5 mysql-connector-java-5.1.40-bin 但是实际上也就是 数据查询和数据处理两种 所以对数 ...
- 在Openstack上创建并访问Kubernetes集群
第一部分:创建集群 在Openstack部署Kubernetes集群运行Nginx容器的步骤,其中包括: 利用Murano部署Kubernetes集群 配置Openstack的安全性使Kubernet ...
- javascript根据元素自定义属性获取元素,操作元素
写在前面:给某个或多个元素自定义属性data-tar,想获取data-tar='123'的元素来进行进一步的操作,如何实现? function getElementByAttr(tag,attr,va ...
- js实现浏览器通知功能
概述 Notification API是浏览器的通知接口,用于在用户的桌面(而不是网页上)显示通知信息,桌面电脑和手机都适用,比如通知用户收到了一封Email.具体的实现形式由浏览器自行部署,对于手机 ...
- c# PictureBox 的图像上使用鼠标画矩形框
C# 中在图像上画框,通过鼠标来实现主要有四个消息响应函数MouseDown, MouseMove, MouseUp, Paint重绘函数实现.当鼠标键按下时开始画框,鼠标键抬起时画框结束. Poin ...
- 9.XML文件解析
一.XML简介 XML(EXtensible Markup Language),可扩展标记语言 特点:XML与操作系统.编程语言的开发平台无关 实现不同系统之间的数据交换 作用:数据交互 配置应用程序 ...