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. node进程一些信号的意义

    1.SIGINT这个信号是系统默认信号,代表信号中断,就是ctrl+c: 2.SIGQUIT 3.SIGTERM 4.exit

  2. android 学习路线

    转载来源:https://blog.csdn.net/lixuce1234/article/details/77947405 jixiaohua发了一篇一个老鸟也发了一份他给公司内部小伙伴整理的路线图 ...

  3. anaconda安装教程、管理虚拟环境

    原文链接:https://blog.csdn.net/ITLearnHall/article/details/81708148 另可参看文章:https://www.cnblogs.com/jonin ...

  4. Asp.Netcore使用Filter来实现接口的全局异常拦截,以及前置拦截和后置拦截

    原文链接:https://blog.csdn.net/qq_38762313/article/details/85234594 全局异常拦截器:       解决写每个接口都需要去做容错而添加try{ ...

  5. #import,#include与@class的区别

    1.#include是C中用来引用文件的关键字,而#import是obj-c中用来代替include的关键字.#import可以确保同一个文件只能被导入一次,从而避免了使用#include容易引起的重 ...

  6. 2018-2-13-win10-uwp-BadgeLogo-颜色

    title author date CreateTime categories win10 uwp BadgeLogo 颜色 lindexi 2018-2-13 17:23:3 +0800 2018- ...

  7. elasticsearch索引清理脚本shell

    es-index-clear.sh: #!/bin/bash#----------------------------------------------# Module: es-index-clea ...

  8. 二、jquery Try{}catch(e){}

    一.Try{}catch(e){} try{ $.each($("div"),function(i,item){ if(...){ throw("异常信息"); ...

  9. Spring之控制反转——IoC、面向切面编程——AOP

      控制反转——IoC 提出IoC的目的 为了解决对象之间的耦合度过高的问题,提出了IoC理论,用来实现对象之间的解耦. 什么是IoC IoC是Inversion of Control的缩写,译为控制 ...

  10. UiAutomator和Appium之间的区别2

    UiAutomator和Appium之间的区别和联系 联系: 在Android端,appium基于WebDriver协议,利用Bootstrap.jar,最后通过调⽤用UiAutomator的命令,实 ...