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的更多相关文章

  1. 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_{ ...

  2. gym101532 2017 JUST Programming Contest 4.0

    台州学院ICPC赛前训练5 人生第一次ak,而且ak得还蛮快的,感谢队友带我飞 A 直接用claris的模板啊,他模板确实比较强大,其实就是因为更新的很快 #include<bits/stdc+ ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. gym101343 2017 JUST Programming Contest 2.0

    A.On The Way to Lucky Plaza  (数论)题意:m个店 每个店可以买一个小球的概率为p       求恰好在第m个店买到k个小球的概率 题解:求在前m-1个店买k-1个球再*p ...

随机推荐

  1. 牛逼哄哄的 API 网关是什么鬼?面试必问!

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 作者:aCoder2013 github.com/aCoder2013/blog/issues/35 前言 假设你正在开发一 ...

  2. 2019 Multi-University Training Contest 1 - 1004 - Vacation - 二分 - 思维

    http://acm.hdu.edu.cn/showproblem.php?pid=6581 一开始想了好几个假算法.但是启发了一下潘哥,假如时间知道的话就可以从头开始确定各个车的位置.那么直接 \( ...

  3. go web编程——实现一个简单分页器

    在go web编程中,当需要展示的列表数据太多时,不可避免需要分页展示,可以使用Go实现一个简单分页器,提供各个数据列表展示使用.具体需求:1. 可展示“首页”和“尾页”.2. 可展示“上一页”和“下 ...

  4. c# 添加数据

    /// <summary> /// 新增一条省份记录 /// </summary> /// <param name="model"></p ...

  5. Linux笔记1-简介

    以下为观看兄弟连视频教程所记. 1.简介 1965年,MIT.GE.AT&T的贝尔实验室 --> Multics 分时.庞大 1969年,贝尔实验室的肯·汤普森 --> Unix ...

  6. Polish orthography

    Computer encoding[edit] There are several different systems for encoding the Polish alphabet for com ...

  7. sd卡无法启动及zc706更改主频后可以进入uboot无法启动kernel的坑

    好长的标题 +_+ 1.sd卡无法启动 起因:kernel底下通过dd测试速度,擦写了sd卡,再启动时发现无法启动 于是重新格式化,再将BOOT.bin 相关dtb u-rootfs zImage和u ...

  8. robotframework

    常用关键字* Settings * Library Selenium2Library1* Keywords * 打开浏览器 [Arguments] ${url} ${browser} [Documen ...

  9. 对于一般情况X1+X2+X3+……+Xn=m 的正整数解有 (m-1)C(n-1) 它的非负整数解有 (m+n-1)C(n-1)种

    对于一般情况X1+X2+X3+……+Xn=m 的正整数解有 (m-1)C(n-1) 它的非负整数解有 (m+n-1)C(n-1)种

  10. maven clean后 编译报错

    <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <config ...