Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#171

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

#171

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions AK4TRL/HDU 5672 String.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
int T,k,H[300];
char s[1000005];
int main(){
#ifdef ak4trl
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
scanf("%d",&T);
while(T--) {
scanf("%s%d",s+1,&k);
int n = strlen(s+1);
memset(H,0,sizeof(H));
int r = 0,cnt = 0;
ll ans = 0 ;
for(int l = 1;l<=n;l++) {
while(cnt<k&&r<n) {
++r;
if(++H[s[r]]==1) cnt++;
}
if(cnt<k) break;
ans = ans+n-r+1;
if(--H[s[l]] == 0) --cnt;
}
cout<<ans<<endl;
}

return 0;
}
50 changes: 50 additions & 0 deletions AK4TRL/HDU 5676 ztr loves lucky numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//暴力,先把所有情况与处理出来,再根据给出数据判断数字位置
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
typedef long long ll;
ll flag[100000], cnt;
void dfs(int len, int mid, int numc, ll num){
if(numc == len){
flag[cnt++] = num;
return ;
}
else{
if(mid > 0)
dfs(len, mid-1, numc + 1, num * 10 + 4);
if(len - numc > mid)
dfs(len, mid, numc + 1, num * 10 + 7);
}
return ;
}
void init(){
for(int i = 2; i <= 18; i += 2)
dfs(i,i/2,0,0);
std::sort(flag,flag+cnt);
}
int main(){
#ifdef hantai
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cnt = 0;
init();
int t;
std::scanf("%d",&t);
while(t--){
ll a;
std::cin >> a;
ll id = std::lower_bound(flag,flag+cnt,a)-flag;
if(a >= 1e18)
puts("44444444447777777777");
else
std::printf("%lld\n",flag[id]);
}

return 0;
}
69 changes: 69 additions & 0 deletions AK4TRL/POJ 3255 次短路
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include<cstdio>
#include<cstring>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<sstream>
#define INF 0x3f3f3f3f
using namespace std;
const int N = 1001 ;
int tn , n , m , k , tcase = 0 ;

struct edge{
int to , cost ;
edge(){} edge(int a , int b) : to(a) , cost(b) {}
} ;
typedef pair<int , int> pii ;
vector<edge> g[5005] ;
int d[5005] , d2[5005] ;

void dijkstra()
{
priority_queue<pii , vector<pii> , greater<pii> > que ;
fill(d,d+n,INF) ;
fill(d2,d2+n,INF) ;
d[0] = 0 ;
que.push(pii(0,0));
while(!que.empty())
{
pii p = que.top() ;
que.pop() ;
int v = p.second , td = p.first ;
if(d2[v] < td)
continue ;
for(int i = 0 ; i < g[v].size() ; ++i)
{
edge &e = g[v][i] ;
int td2 = td + e.cost ;
if(d[e.to] > td2)
swap(d[e.to] , td2), que.push(pii(d[e.to] ,e.to)) ;
if(d2[e.to] > td2 && d[e.to] < td2)
d2[e.to] = td2, que.push(pii(d2[e.to] , e.to)) ;
}
}
cout << d2[n-1] << endl ;
}
int main()
{
#ifdef ONLINEJUDGE_AK4TRl
freopen("input.txt","r",stdin);
#endif
cin >> n >> m ;
int a , b , c ;
for(int i = 0 ; i < m ; ++i)
{
cin >> a >> b >> c ;
g[a-1].push_back(edge(b - 1 , c)) ;
g[b-1].push_back(edge(a - 1 , c)) ;
}
dijkstra() ;

return 0;
}