2017 JUST Programming Contest 2.0
B. So You Think You Can Count?
设dp[i]表示以i为结尾的方案数,每个位置最多往前扫10位
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const int mod = 1e9+;
ll dp[maxn];//dp[i]表示以i结尾的方案数。
int num[];
char s[maxn];
int main()
{
int n;
cin >> n;
cin >> s + ;
dp[] = ;
for(int i = ;i <= n;i++)
{
memset(num, ,sizeof(num));
for(int j = i;j > ;j--)
{
num[s[j]-'']++;
if(num[s[j]-''] > ) break;
dp[i] = (dp[i] + dp[j-])%mod;
}
}
cout << dp[n] << endl;
return ;
}
C. MRT Map
思路:存下每个字符串26个字母出现的次数,然后建边的时候计算一遍权值,然后dijkstra就好了。
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int maxn = 5e5 + ;
const int INF = 0x3f3f3f3f;
int n, m;
int num[maxn][];
int cal(int u, int v)
{
int ans = ;
for(int i = ;i < ;i++){
if(num[u][i] && num[v][i])
ans++;
}
return ans;
}
struct edge{
int to;
int cost;
}e;
vector <edge> G[maxn];
int d[maxn];
void add(int u, int v)
{
e.to = v;
e.cost = cal(u,v);
G[u].push_back(e);
}
void dijkstra(int s)
{
priority_queue<P,vector<P>,greater<P> > que;
fill(d ,d + n + ,INF);
d[s] = ;
que.push(P(,s));
while(!que.empty())
{
P p= que.top();que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i = ;i < G[v].size();i++)
{
edge e = G[v][i];;
if(d[e.to] > d[v] +e.cost)
{
d[e.to]= d[v] + e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> n >> m;
string a;
for(int i = ;i <= n;i++)
{
cin >> a;
int len = a.size();
for(int j = ;j < len;j++){
if(a[j] >= 'a' && a[j] <= 'z') num[i][a[j] - 'a']++;
else num[i][a[j] - 'A']++;
} }
for(int i = ;i <= m;i++)
{
int u, v;
cin >> u >> v;
add(u, v);
add(v, u);
}
int s, t;
cin >> s >> t;
dijkstra(s);
cout << d[t] << endl;
return ;
}
D. Husam's Bug跑
签到题1
#include<bits/stdc++.h>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
string s;
int cnt = , num = , sum = ;//字母 数字 特殊符号
cin >> s;
for(int i = ;i < s.size();i++)
{
if(s[i] >= 'a' && s[i] <= 'z') cnt++;
if(s[i] >= 'A' && s[i] <= 'Z') cnt++;
if(s[i] >= '' && s[i] <= '') num++;
if(s[i] == '@' || s[i] == '?' || s[i] == '!') sum++;
}
if(cnt < ){
cout << "The last character must be a letter." << endl;
}
else if(num < ){
cout << "The last character must be a digit." << endl;
}
else if(sum < ){
cout << "The last character must be a symbol." << endl;
}
else cout << "The last character can be any type." << endl;
}
return ;
}
E. Abdalrahman Ali Bugs
思路:容易得出X是在 2 - 最大出现次数之间,直接暴力枚举所有答案取最优解。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[];
ll check(ll x)
{
ll ans = ;
for(int i = ;i < ;i++){
ans += (num[i] % x) * num[i];
}
return ans;
}
int main()
{
std::ios::sync_with_stdio(false);
string a;
cin >> a;
ll mx = ;
for(int i = ;i < a.size();i++)
{
int t = a[i] - 'a';
num[t]++;
mx = max(num[t],mx);
}
ll x = ;
ll ans = check(x);
for(ll i = ;i <= mx;i++){
if(check(i) < ans){
x = i;
ans = check(i);
}
}
cout << x << endl;
return ;
}
F. Certifications
思路:在a数组中二分一个大于X的最小值,找不到则输出那一串。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
ll a[maxn];
const ll INF = 1e18;
int main()
{
std::ios::sync_with_stdio(false);
int n, m;
cin >> n;
for(int i = ;i < n;i++){
cin >> a[i];
}
sort(a, a + n);
a[n] = INF;
cin >> m;
while(m--)
{
int x;
cin >> x;
int l = , r = n, o = ;
while(l <= r){
int mid = (l + r) / ;
if(a[mid] >= x) r = mid - , o = mid;
else l = mid + ;
// cout << o << endl;
}
if(a[o] == INF) cout << "Dr. Samer cannot take any offer :(." << endl;
else cout << a[o] << endl;
}
return ;
}
G. In the Chairman's office
qaq签到题2。
H. Give Me This Pizza
思路:右边最近的较大值,这不是很白的一个单调栈么,暑假队内赛第一场的A,相似度80%。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int st[maxn], ans[maxn], a[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin >> n;
memset(ans,-,sizeof(ans));
for(int i = ;i < n;i++) cin >> a[i];
int cnt = ;
for(int i = ;i < n;i++)
{
while(cnt > && a[st[cnt]] < a[i]){
ans[st[cnt--]] = i;
}
st[++cnt] = i;
}
for(int i = ;i < n;i++){
if(ans[i] == -) cout << ans[i] << " ";
else cout << a[ans[i]] << " ";
}
return ;
}
I. Husam and the Broken Present 1
思路:对角线元素是平方和,对其开根号即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int ans[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin >> n;
int a;
for(int i = ;i < n;i++){
for(int j = ;j < n;j++){
cin >> a;
if(i == j) ans[i] = sqrt(a);
}
}
for(int i = ;i < n;i++){
if(i == n - ) cout << ans[i] << endl;
else cout << ans[i] << " ";
}
return ;
}
K.Counting Time
思路:可以很暴力的一道题,9!枚举出3*3矩阵所有状态,判断和题目所给的矩阵非0位相不相等并且满不满足题意。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mp[][];
int mp2[][];
int a[];
int vis[];
int ans;
int dx[] = {, , , -, , , -, -};
int dy[] = {-, , , , -, , , -}; bool check(int x, int y){
if(x >= && x < && y >= && y < ) return true;
else return false;
}
bool check1(int x, int y,char val)
{
if(mp2[x][y] == ) return true;
for(int i = ;i < ;i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if(check(nx, ny) && mp2[nx][ny] == val + ) return true;
}
return false;
}
bool check3(){
for(int i = ;i < ;i++){
for(int j = ;j < ;j++){
if(!check1(i, j, mp2[i][j])) return false;
}
}
return true;
}
int check2()
{
for(int i = ;i < ;i++){
int x = i / ;
int y = i % ;
mp2[x][y] = a[i];
if(mp[x][y] != a[i] && mp[x][y] != ) return ;
}
if(check3()) return ;
else return ;
}
void dfs(int pos)
{
if(pos >= ){
ans += check2();
return;
}
for(int i = ;i <= ;i++)
{
if(!vis[i]) {
a[pos] = i;
vis[i] = ;
dfs(pos + );
vis[i] = ;
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
char c;
for(int i = ;i < ;i++){
for(int j = ;j < ;j++)
{
cin >> c;
int t = c - '';
mp[i][j] = t;
}
}
dfs();
cout << ans << endl;
return ;
}
2017 JUST Programming Contest 2.0的更多相关文章
- 2017 JUST Programming Contest 2.0 题解
[题目链接] A - On The Way to Lucky Plaza 首先,$n>m$或$k>m$或$k>n$就无解. 设$p = \frac{A}{B}$,$ans = C_{ ...
- gym101532 2017 JUST Programming Contest 4.0
台州学院ICPC赛前训练5 人生第一次ak,而且ak得还蛮快的,感谢队友带我飞 A 直接用claris的模板啊,他模板确实比较强大,其实就是因为更新的很快 #include<bits/stdc+ ...
- 2017 JUST Programming Contest 3.0 B. Linear Algebra Test
B. Linear Algebra Test time limit per test 3.0 s memory limit per test 256 MB input standard input o ...
- 2017 JUST Programming Contest 3.0 I. Move Between Numbers
I. Move Between Numbers time limit per test 2.0 s memory limit per test 256 MB input standard input ...
- 2017 JUST Programming Contest 3.0 D. Dice Game
D. Dice Game time limit per test 1.0 s memory limit per test 256 MB input standard input output stan ...
- 2017 JUST Programming Contest 3.0 H. Eyad and Math
H. Eyad and Math time limit per test 2.0 s memory limit per test 256 MB input standard input output ...
- 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester
K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard i ...
- 2017 JUST Programming Contest 3.0 E. The Architect Omar
E. The Architect Omar time limit per test 1.0 s memory limit per test 256 MB input standard input ou ...
- gym101343 2017 JUST Programming Contest 2.0
A.On The Way to Lucky Plaza (数论)题意:m个店 每个店可以买一个小球的概率为p 求恰好在第m个店买到k个小球的概率 题解:求在前m-1个店买k-1个球再*p ...
随机推荐
- SpringBoot 接口并行高效聚合
转自:juejin.im/post/5d064b90e51d45777540fda7 背景 接口开发是后端开发中最常见的场景, 可能是RESTFul接口, 也可能是RPC接口. 接口开发往往是从各处捞 ...
- express框架中router组件的app.use和app.get
首先看例子: var express = require('express'); var router = express.Router(); var index = require('./route ...
- Day3---Python的time库的一些简单函数以及用法
time库的一些函数 time.time () : 获取当前时间戳,即计算机内部时间值,浮点数 >>>import time >>> time.time() 1 ...
- redis缓存架构-03-redis下的replication以及master+slave
1.master和slave的读写分离(水平扩容支持读高并发) 2.master主从复制流程 master开始复制给slave前的认证流程 master向slave复制流程 2.1 无磁盘化复制配置 ...
- Kernel Page Global Directory (PGD) of Page table of Process created in Linux Kernel
Kernel Page Global Directory (PGD) of User process created 在早期版本: 在fork一个进程的时候,必须建立进程自己的内核页目录项(内核页目录 ...
- sqlserver创建索引语句
CREATE INDEX PersonIndex ON 表名 (字段名) DROP INDEX PersonIndex ON 表名
- 克隆虚拟机(centos7)
当我们做分布式测试时,需要多个节点(虚拟机),除了一个个虚拟机重新安装外,还可以从一个虚拟机镜像克隆出新的虚拟机 本例中要从名为master1的虚拟机克隆一个名为node1的 输入新的虚拟机名称和文件 ...
- 重命名sql数据库
use master select spid from master.dbo.sysprocesses where dbid=db_id('TW') 查看连接,杀死线程 use master kill ...
- NGUI的widget的使用
一,我们看看widget有什么属性,如下图: 二,Pivot是什么意思? 我们都知道在Untiy3D中有一个中央坐标点,而这个Pivot这个就是选择控件的某一个点与中央坐标点定位. 如下图区别: 当你 ...
- JS方法使用中文出参数 ,报错异常
正常这样加载数字没问题,但是当参数是中文时就会报错 <li onclick='onSeach(‘’" + name+ "');'>" + name+ &quo ...